Пример #1
0
        /// <summary>
        /// Get information about a media object. The returned type key will allow you to differentiate between image and video media.
        /// Note: if you authenticate with an OAuth Token, you will receive the user_has_liked key which quickly tells you whether the current user has liked this media item.
        /// </summary>
        /// <param name="mediaId">Media Id.</param>
        /// <returns>JSON result string.</returns>
        public async Task <string> GetMediaInfoAsync(string mediaId)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                var response = await httpClient.GetAsync(MediaEndpointsUrlsFactory.CreateMediaInfoUrl(mediaId, this.accessToken));

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(responseContent);
                }
                else
                {
                    throw new InstagramAPIException(responseContent);
                }
            }
        }
        /// <summary>
        /// Get information about a media object. The returned type key will allow you to differentiate between image and video media.
        /// Note: if you authenticate with an OAuth Token, you will receive the user_has_liked key which quickly tells you whether the current user has liked this media item.
        /// The public_content permission scope is required to get a media that does not belong to the owner of the access_token.
        /// </summary>
        /// <param name="mediaId">Media Id.</param>
        /// <param name="accessToken" type="string">
        ///     <para>
        ///         A valid access token.
        ///     </para>
        /// </param>
        /// <returns>JSON result string.</returns>
        public async Task <string> GetMediaInfoAsync(string mediaId, string accessToken)
        {
            using (HttpClient httpClient = new HttpClient())
            {
                Uri uri = MediaEndpointsUrlsFactory.CreateMediaInfoUrl(mediaId, accessToken);
                if (this.EnforceSignedRequests)
                {
                    uri = uri.AddParameter("sig", Utilities.GenerateSig(string.Format(InstagramAPIEndpoints.MediaInfoEndpoint, mediaId), this.ClientSecret, uri.Query));
                }
                var response = await httpClient.GetAsync(uri);

                string responseContent = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {
                    return(responseContent);
                }
                else
                {
                    throw new InstagramAPIException(responseContent);
                }
            }
        }