예제 #1
0
파일: UnMedia.cs 프로젝트: yuvrajb/InstaAPI
        /******************************************************** 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);
        }
예제 #2
0
        /******************************************************** 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("client_id", Config.GetClientId());

                // 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);
        }
예제 #3
0
        /******************************************************** 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);
        }