public async Task <IResult <InstaDirectInboxContainer> > GetDirectInboxAsync() { try { var directInboxUri = UriCreator.GetDirectInboxUri(); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, directInboxUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsyncWithoutDelay(request); var json = await response.Content.ReadAsStringUnZipAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaDirectInboxContainer>(response, json)); } var inboxResponse = JsonConvert.DeserializeObject <InstaDirectInboxContainerResponse>(json); var converter = ConvertersFabric.Instance.GetDirectInboxConverter(inboxResponse); return(Result.Success(converter.Convert())); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaDirectInboxContainer>(exception.Message)); } }
/// <summary> /// Get the global story feed which contains everyone you follow. /// Note that users will eventually drop out of this list even though they /// still have stories.So it's always safer to call getUserStoryFeed() if /// a specific user's story feed matters to you. /// </summary> /// <returns></returns> public async Task <IResult <InstaFeed> > GetReelsTrayFeed() { var feed = new InstaFeed(); try { var fields = new Dictionary <string, string> { { "is_prefetch", "0" }, { "supported_capabilities_new", JsonConvert.SerializeObject(InstaApiConstants.SUPPORTED_CAPABILITIES) }, { "_csrftoken", _user.CsrfToken }, { "_uuid", _httpRequestProcessor.RequestMessage.uuid }, }; var request = HttpHelper.GetDefaultRequest(HttpMethod.Post, new Uri("https://i.instagram.com/api/v1/feed/reels_tray/"), _deviceInfo, fields); var response = await _httpRequestProcessor.SendAsyncWithoutDelay(request); var json = await response.Content.ReadAsStringUnZipAsync(); //if (response.StatusCode != HttpStatusCode.OK) // return Result.UnExpectedResponse<InstaFeed>(response, json); //var feedResponse = JsonConvert.DeserializeObject<InstaFeedResponse>(json, new InstaFeedResponseDataConverter()); //feed = ConvertersFabric.Instance.GetFeedConverter(feedResponse).Convert(); return(Result.Success(feed)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, feed)); } }
/// <summary> /// Get your "home screen" timeline feed. /// /// An associative array with following keys (all of them are optional): /// "latest_story_pk" The media ID in Instagram's internal format (ie "3482384834_43294"); /// /// "seen_posts" One or more seen media IDs; /// /// "unseen_posts" One or more unseen media IDs; /// /// "is_pull_to_refresh" Whether this call was triggered by a refresh; /// /// "push_disabled" Whether user has disabled PUSH; /// /// "recovered_from_crash" Whether the app has recovered from a crash/was killed by Android /// memory manager/force closed by user/just installed for the first time; /// /// "feed_view_info" DON'T USE IT YET. /// </summary> /// <returns></returns> public async Task <IResult <InstaFeed> > GetTimelineFeedAsync(Dictionary <string, string> options = null) { var feed = new InstaFeed(); try { var request = HttpHelper.GetDefaultRequest(HttpMethod.Post, new Uri("https://i.instagram.com/api/v1/feed/timeline/"), _deviceInfo); request.Headers.Add("X-Ads-Opt-Out", "0"); request.Headers.Add("X-Google-AD-ID", _httpRequestProcessor.RequestMessage.advertising_id); request.Headers.Add("X-DEVICE-ID", _httpRequestProcessor.RequestMessage.uuid); var fields = new Dictionary <string, string> { { "_csrftoken", _user.CsrfToken }, { "_uuid", _httpRequestProcessor.RequestMessage.uuid }, { "is_prefetch", "0" }, { "phone_id", _httpRequestProcessor.RequestMessage.phone_id }, { "device_id", _httpRequestProcessor.RequestMessage.device_id }, { "client_session_id", _httpRequestProcessor.RequestMessage.session_id }, { "battery_level", "100" }, { "is_charging", "1" }, { "will_sound_on", "1" }, { "is_on_screen", "true" }, { "timezone_offset", InstaApiConstants.TIMEZONE_OFFSET.ToString() }, // date('Z') { "is_async_ads", "0" }, { "is_async_ads_double_request", "0" }, { "is_async_ads_rti", "0" }, { "rti_delivery_backend", "" }, }; if (options != null && options.ContainsKey("latest_story_pk")) { fields.Add("latest_story_pk", options["latest_story_pk"]); } /* * if ($maxId !== null) { * $request->addPost('reason', 'pagination'); * $request->addPost('max_id', $maxId); * $request->addPost('is_pull_to_refresh', '0'); * * } elseif (!empty($options['is_pull_to_refresh'])) { * $request->addPost('reason', 'pull_to_refresh'); * $request->addPost('is_pull_to_refresh', '1'); * * } elseif (isset($options['is_pull_to_refresh'])) { * $request->addPost('reason', 'warm_start_fetch'); * $request->addPost('is_pull_to_refresh', '0'); * * } else { * $request->addPost('reason', 'cold_start_fetch'); * $request->addPost('is_pull_to_refresh', '0'); * } */ //if (options != null && options.ContainsKey("is_pull_to_refresh")) //{ // if (options["is_pull_to_refresh"] != null) // { // fields.Add("reason", "pull_to_refresh"); // fields.Add("is_pull_to_refresh", "1"); // } // else // { // fields.Add("reason", "warm_start_fetch"); // fields.Add("is_pull_to_refresh", "0"); // } //} //else //{ // fields.Add("reason", "cold_start_fetch"); // fields.Add("is_pull_to_refresh", "0"); //} fields.Add("unseen_posts", ""); fields.Add("feed_view_info", ""); if (options != null && options.ContainsKey("recovered_from_crash")) { fields.Add("recovered_from_crash", "1"); } request.Content = new FormUrlEncodedContent(fields); var response = await _httpRequestProcessor.SendAsyncWithoutDelay(request); var json = await response.Content.ReadAsStringUnZipAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaFeed>(response, json)); } var feedResponse = JsonConvert.DeserializeObject <InstaFeedResponse>(json, new InstaFeedResponseDataConverter()); feed = ConvertersFabric.Instance.GetFeedConverter(feedResponse).Convert(); return(Result.Success(feed)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, feed)); } }