private List <InstagramMedia> GetFeedDataFromInstagram()
        {
            var service = InstagramService.CreateFromAccessToken(siteSettingsHelper.GetCurrentSiteInstagramAccessToken());

            var userResponse = service.Users.GetSelf();

            // Temporary list for storing the retrieved media
            var media = new List <InstagramMedia>();

            // Find the first user with the specified username
            var user = userResponse.Body.Data;

            if (user != null)
            {
                // Declare the initial search options
                var options = new InstagramUserRecentMediaOptions
                {
                    Count = siteSettingsHelper.GetCurrentSiteInstagramMaxItems(),
                };

                var mediaResponse = service.Users.GetRecentMedia(user.Id, options);

                // Add the media to the list
                media.AddRange(mediaResponse.Body.Data);
            }

            CacheManager.Add(
                GetCacheKey(),
                media,
                CacheItemPriority.Normal,
                null,
                new AbsoluteTime(TimeSpan.FromMinutes(siteSettingsHelper.GetCurrentSiteInstagramExpiration())));

            return(media);
        }
Esempio n. 2
0
        private List <InstagramMedia> GetFeedDataFromInstagram()
        {
            var service = InstagramService.CreateFromAccessToken(instagramConfig.AccessToken);

            var userResponse = service.Users.Search(Username);

            // Temporary list for storing the retrieved media
            var media = new List <InstagramMedia>();

            // Find the first user with the specified username
            var user = userResponse.Body.Data.FirstOrDefault(x => x.Username == Username);

            if (user != null)
            {
                // Declare the initial search options
                var options = new InstagramUserRecentMediaOptions
                {
                    Count = instagramConfig.MaxItems,
                };

                var mediaResponse = service.Users.GetRecentMedia(user.Id, options);

                // Add the media to the list
                media.AddRange(mediaResponse.Body.Data);
            }

            CacheManager.Add(
                GetCacheKey(),
                media,
                CacheItemPriority.Normal,
                null,
                new AbsoluteTime(TimeSpan.FromMinutes(instagramConfig.Expiration)));

            return(media);
        }
 /// <summary>
 /// Gets the most recent media of the user with the specified ID.
 /// </summary>
 /// <param name="userId">The ID of the user.</param>
 /// <param name="options">The search options with any optional parameters.</param>
 public InstagramRecentMediaResponse GetRecentMedia(long userId, InstagramUserRecentMediaOptions options)
 {
     return(InstagramRecentMediaResponse.ParseJson(Raw.GetRecentMedia(userId + "", options).Body));
 }
 /// <summary>
 /// Gets the the most recent media of the authenticated user.
 /// </summary>
 /// <param name="options">The search options with any optional parameters.</param>
 public InstagramRecentMediaResponse GetRecentMedia(InstagramUserRecentMediaOptions options)
 {
     return(InstagramRecentMediaResponse.ParseJson(Raw.GetRecentMedia("self", options).Body));
 }
 /// <summary>
 /// Get the most recent media published by a user.
 /// </summary>
 /// <param name="identifier">The identifier of the user.</param>
 /// <param name="options">The search options with any optional parameters.</param>
 /// <returns>Returns the raw JSON response from the API.</returns>
 public SocialHttpResponse GetRecentMedia(string identifier, InstagramUserRecentMediaOptions options)
 {
     return(Client.DoAuthenticatedGetRequest("https://api.instagram.com/v1/users/" + identifier + "/media/recent/", options));
 }