/******************************************************** GETTERS *********************************************************/ /// <summary> /// <para>gets the list of users that a user follows</para> /// </summary> /// <param name="UserId"></param> /// <param name="Parameters"></param> /// <returns></returns> public UserFollows GetUserFollows(String UserId, GetUserFollowsParameters Parameters) { UserFollows Follows = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(); BaseUri.Scheme = Config.GetUriScheme(); BaseUri.Host = Config.GetApiUriString(); BaseUri.Path = "users/" + UserId + "/follows"; // SET UP QUERY String NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("access_token", AuthorisedUser.AccessToken); QueryString.Add("count", Parameters.Count.ToString()); QueryString.Add("cursor", Parameters.NextCursor); // SET THE QUERY StringS BaseUri.Query = QueryString.ToString(); // CREATE NEW USER FOLLOWS OBJECT Follows = new UserFollows(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Follows.Meta = Meta; // CREATE PAGINATION OBJECT PaginationCursorData Pagination = new PaginationCursorData(); Pagination.NextUrl = ParsedJson.pagination.next_url; Pagination.NextCursor = ParsedJson.pagination.next_cursor; Follows.Pagination = Pagination; // CREATE DATA LIST List <User> Data = new List <User>(); foreach (dynamic EachUser in ParsedJson.data) { // CREATE AND FILL USER OBJECT User User = new User(); User.UserName = EachUser.username; User.Bio = EachUser.bio; User.Website = EachUser.website; User.ProfilePicture = EachUser.profile_picture; User.FullName = EachUser.full_name; User.Id = EachUser.id; // ADD USER TO THE LIST Data.Add(User); } Follows.Data = Data; } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; Follows.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(Follows); }
/******************************************************** GETTERS **********************************************************/ /// <summary> /// <para>gets information about a location</para> /// </summary> /// <param name="LocationId"></param> /// <returns></returns> public LocationInfoData GetLocationInformation(String LocationId) { LocationInfoData LocInfo = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(Config.GetUriScheme() + "://" + Config.GetApiUriString() + "/locations/" + LocationId); // SET UP QUERY STRING NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("access_token", AuthorisedUser.AccessToken); // SET THE QUERY STRINGS BaseUri.Query = QueryString.ToString(); // CREATE NEW FEEDS OBJECT AND FILL IN DATA LocInfo = new LocationInfoData(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; LocInfo.Meta = Meta; // SET DATA LocationData Data = new LocationData(); Data.Id = ParsedJson.data.id; Data.Name = ParsedJson.data.name; Data.Latitude = ParsedJson.data.latitude; Data.Longitude = ParsedJson.data.longitude; LocInfo.Data = Data; } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; LocInfo.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(LocInfo); }
/******************************************************** GETTERS *********************************************************/ /// <summary> /// <para>gets the basic user information - identified by UserId</para> /// </summary> /// <param name="UserId"></param> /// <returns></returns> public User GetUserInformation(String UserId) { User RequestedUser = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(); BaseUri.Scheme = Config.GetUriScheme(); BaseUri.Host = Config.GetApiUriString(); BaseUri.Path = "users/" + UserId + "/"; // SET UP QUERY String NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("access_token", AuthorisedUser.AccessToken); // SET THE QUERY StringS BaseUri.Query = QueryString.ToString(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE NEW USER OBJECT AND FILL IN DATA RequestedUser = new User(); RequestedUser.Id = ParsedJson.id; RequestedUser.UserName = ParsedJson.data.username; RequestedUser.FullName = ParsedJson.data.full_name; RequestedUser.Bio = ParsedJson.data.bio; RequestedUser.Website = ParsedJson.data.website; RequestedUser.ProfilePicture = ParsedJson.data.profile_picture; RequestedUser.MediaCount = ParsedJson.data.counts.media; RequestedUser.FollowsCount = ParsedJson.data.counts.follows; RequestedUser.FollowedByCount = ParsedJson.data.counts.followed_by; // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; RequestedUser.Meta = Meta; } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW USER OBJECT AND FILL IN DATA RequestedUser = new User(); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; RequestedUser.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(RequestedUser); }
/******************************************************** GETTERS **********************************************************/ /// <summary> /// <para>gets the list of recent comments on a media object</para> /// </summary> /// <param name="MediaId"></param> /// <returns></returns> public MediaComments GetMediaRecentComments(String MediaId) { MediaComments Comments = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(Config.GetUriScheme() + "://" + Config.GetApiUriString() + "/media/" + MediaId + "/comments"); // SET UP QUERY STRING NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("access_token", AuthorisedUser.AccessToken); // SET THE QUERY STRINGS BaseUri.Query = QueryString.ToString(); // CREATE NEW FEEDS OBJECT AND FILL IN DATA Comments = new MediaComments(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Comments.Meta = Meta; // SET FEED DATA List <Comment> Data = new List <Comment>(); foreach (dynamic EachComment in ParsedJson.data) { Comment Comment = new Comment(); Comment.CreatedTime = new DateTime(long.Parse(EachComment.created_time.ToString())); Comment.Id = EachComment.id; Comment.Text = EachComment.text; User CommentedBy = new User(); CommentedBy.Id = EachComment.from.id; CommentedBy.UserName = EachComment.from.username; CommentedBy.ProfilePicture = EachComment.from.profile_picture; CommentedBy.FullName = EachComment.from.full_name; Comment.From = CommentedBy; Data.Add(Comment); } Comments.Data = Data; } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; Comments.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(Comments); }
/******************************************************** GETTERS *********************************************************/ /// <summary> /// <para>gets the media information using media id</para> /// </summary> /// <param name="MediaId"></param> /// <returns></returns> public MediaData GetMediaInformation(String MediaId) { MediaData Media = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(); BaseUri.Scheme = Config.GetUriScheme(); BaseUri.Host = Config.GetApiUriString(); BaseUri.Host += "/media/" + MediaId; // SET UP QUERY STRING NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("client_id", Config.GetClientId()); // SET THE QUERY STRINGS BaseUri.Query = QueryString.ToString(); // CREATE NEW FEEDS OBJECT AND FILL IN DATA Media = new MediaData(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Media.Meta = Meta; // SET FEED DATA Media.Feed = ParseFeed(ParsedJson); } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; Media.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(Media); }
/******************************************************** GETTERS **********************************************************/ /// <summary> /// <para>gets information about a tag object</para> /// </summary> /// <param name="TagName"></param> /// <returns></returns> public TagData GetTagInformation(String TagName) { TagData Tag = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(Config.GetUriScheme() + "://" + Config.GetApiUriString() + "/tags/" + TagName); // SET UP QUERY STRING NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("client_id", Config.GetClientId()); // SET THE QUERY STRINGS BaseUri.Query = QueryString.ToString(); // CREATE NEW FEEDS OBJECT AND FILL IN DATA Tag = new TagData(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Tag.Meta = Meta; // SET DATA TagInfo TagInfo = new TagInfo(); TagInfo.MediaCount = long.Parse(ParsedJson.data.media_count.ToString()); TagInfo.Name = ParsedJson.data.name; Tag.Data = TagInfo; } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; Tag.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(Tag); }
/******************************************************** GETTERS **********************************************************/ /// <summary> /// <para>gets all the posts of the user - identified by UserId</para> /// </summary> /// <param name="UserId"></param> /// <param name="Parameters"></param> /// <returns></returns> public Feeds GetUserPosts(String UserId, GetUserPostsParameters Parameters) { Feeds UserPosts = null; try { // SET UP REQUEST URI UriBuilder BaseUri = new UriBuilder(); BaseUri.Scheme = Config.GetUriScheme(); BaseUri.Host = Config.GetApiUriString(); BaseUri.Host += "/users/" + UserId + "/media/recent"; // SET UP QUERY STRING NameValueCollection QueryString = System.Web.HttpUtility.ParseQueryString(String.Empty); QueryString.Add("client_id", Config.GetClientId()); QueryString.Add("count", Parameters.Count.ToString()); QueryString.Add("max_timestamp", Parameters.MaxTimeStamp.ToString()); QueryString.Add("min_timestamp", Parameters.MinTimeStamp.ToString()); QueryString.Add("min_id", Parameters.MinId); QueryString.Add("max_id", Parameters.MaxId); // SET THE QUERY STRINGS BaseUri.Query = QueryString.ToString(); // CREATE NEW FEEDS OBJECT AND FILL IN DATA UserPosts = new Feeds(); // SEND REQUEST WebClient Client = new WebClient(); byte[] ResponseData = Client.DownloadData(BaseUri.Uri); String Response = Encoding.UTF8.GetString(ResponseData); // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(Response); // CREATE META OBJECT MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; UserPosts.Meta = Meta; // CREATE PAGINATION OBJECT PaginationIdData Pagination = new PaginationIdData(); Pagination.NextUrl = ParsedJson.pagination.next_url; Pagination.NextMaxId = ParsedJson.pagination.next_max_id; UserPosts.Pagination = Pagination; // SET FEEDS DATA UserPosts.Data = ParseFeeds(ParsedJson); } catch (WebException WEx) { // FETCHES ANY ERROR THROWN BY INSTAGRAM API Stream ResponseStream = WEx.Response.GetResponseStream(); if (ResponseStream != null) { StreamReader ResponseReader = new StreamReader(ResponseStream); if (ResponseReader != null) { // PARSE JSON dynamic ParsedJson = JsonConvert.DeserializeObject(ResponseReader.ReadToEnd()); // CREATE NEW META OBJECT AND FILL IN DATA MetaData Meta = new MetaData(); Meta.Code = ParsedJson.meta.code; Meta.ErrorType = ParsedJson.meta.error_type; Meta.ErrorMessage = ParsedJson.meta.error_message; UserPosts.Meta = Meta; } } } catch (Exception Ex) { Console.WriteLine(Ex.StackTrace); } return(UserPosts); }