Ejemplo n.º 1
0
        public async Task <IResult <InstaFeed> > GetUserTimelineFeedAsync(int maxPages = 0)
        {
            ValidateUser();
            ValidateLoggedIn();
            var userFeedUri = UriCreator.GetUserFeedUri();
            var request     = HttpHelper.GetDefaultRequest(HttpMethod.Get, userFeedUri, _deviceInfo);
            var response    = await _httpClient.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            var feed = new InstaFeed();

            if (response.StatusCode != HttpStatusCode.OK)
            {
                return(Result.Fail(GetBadStatusFromJsonString(json).Message, (InstaFeed)null));
            }
            var feedResponse = JsonConvert.DeserializeObject <InstaFeedResponse>(json,
                                                                                 new InstaFeedResponseDataConverter());
            var converter     = ConvertersFabric.GetFeedConverter(feedResponse);
            var feedConverted = converter.Convert();

            feed.Medias.AddRange(feedConverted.Medias);
            var nextId = feedResponse.NextMaxId;

            while (feedResponse.MoreAvailable && feed.Pages < maxPages)
            {
                if (string.IsNullOrEmpty(nextId))
                {
                    break;
                }
                var nextFeed = await GetUserFeedWithMaxIdAsync(nextId);

                if (!nextFeed.Succeeded)
                {
                    Result.Success($"Not all pages was downloaded: {nextFeed.Info.Message}", feed);
                }
                nextId = nextFeed.Value.NextMaxId;
                feed.Medias.AddRange(
                    nextFeed.Value.Items.Select(ConvertersFabric.GetSingleMediaConverter).Select(conv => conv.Convert()));
                feed.Pages++;
            }
            return(Result.Success(feed));
        }
Ejemplo n.º 2
0
        public async Task <InstaUserFeed> GetUserFeedAsync(int pageCount)
        {
            if (!IsUserAuthenticated)
            {
                throw new Exception("user must be authenticated");
            }
            var feedUrl = $"{InstaApiConstants.INSTAGRAM_URL.TrimEnd('/')}{InstaApiConstants.GET_ALL_POSTFIX}";
            var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, new Uri(feedUrl));

            request.Headers.Add(InstaApiConstants.HEADER_XCSRFToken, _user.Token);
            request.Headers.Add(InstaApiConstants.HEADER_XInstagramAJAX, "1");
            request.Headers.Add(InstaApiConstants.HEADER_XRequestedWith, InstaApiConstants.HEADER_XMLHttpRequest);
            var response = await _httpClient.SendAsync(request);

            var json = await response.Content.ReadAsStringAsync();

            var feedResponse = JsonConvert.DeserializeObject <InstaFeedResponse>(json);
            var converter    = ConvertersFabric.GetFeedConverter(feedResponse);

            return(converter.Convert());
        }