/// <summary> /// Get self account information like joined date or switched to business account date /// </summary> public async Task <IResult <InstaWebAccountInfo> > GetAccountInfoAsync() { InstaUserAuthValidator.Validate(userAuthValidate); try { var instaUri = InstaWebUriCreator.GetAccountsDataUri(); var request = httpHelper.GetWebRequest(HttpMethod.Get, instaUri, deviceInfo); var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false); var html = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { return(Result.Fail($"Error! Status code: {response.StatusCode}", default(InstaWebAccountInfo))); } var json = html.GetJson(); if (json.IsEmpty()) { return(Result.Fail("Json response isn't available.", default(InstaWebAccountInfo))); } var obj = JsonConvert.DeserializeObject <InstaWebContainerResponse>(json); if (obj.Entry?.SettingsPages != null) { var first = obj.Entry.SettingsPages.FirstOrDefault(); if (first != null) { return(Result.Success(InstaConvertersFabric.Instance.GetWebAccountInfoConverter(first).Convert())); } } return(Result.Fail("Date joined isn't available.", default(InstaWebAccountInfo))); } catch (HttpRequestException httpException) { logger?.LogError(httpException, "Error"); return(Result.Fail(httpException, default(InstaWebAccountInfo), ResponseType.NetworkProblem)); } catch (Exception exception) { logger?.LogError(exception, "Error"); return(Result.Fail(exception, default(InstaWebAccountInfo))); } }
private async Task <IResult <InstaWebData> > GetFormerAsync(InstaWebType type, PaginationParameters paginationParameters) { InstaUserAuthValidator.Validate(userAuthValidate); var webData = new InstaWebData(); try { if (paginationParameters == null) { paginationParameters = PaginationParameters.MaxPagesToLoad(1); } InstaWebData Convert(InstaWebSettingsPageResponse settingsPageResponse) { return(InstaConvertersFabric.Instance.GetWebDataConverter(settingsPageResponse).Convert()); } Uri CreateUri(string cursor = null) { switch (type) { case InstaWebType.FormerBioTexts: return(InstaWebUriCreator.GetFormerBiographyTextsUri(cursor)); case InstaWebType.FormerLinksInBio: return(InstaWebUriCreator.GetFormerBiographyLinksUri(cursor)); case InstaWebType.FormerUsernames: return(InstaWebUriCreator.GetFormerUsernamesUri(cursor)); case InstaWebType.FormerFullNames: return(InstaWebUriCreator.GetFormerFullNamesUri(cursor)); case InstaWebType.FormerPhones: return(InstaWebUriCreator.GetFormerPhoneNumbersUri(cursor)); case InstaWebType.FormerEmails: return(InstaWebUriCreator.GetFormerEmailsUri(cursor)); default: return(InstaWebUriCreator.GetFormerBiographyLinksUri(cursor)); } } var request = await GetRequest(CreateUri(paginationParameters?.NextMaxId)).ConfigureAwait(false); if (!request.Succeeded) { if (request.Value != null) { return(Result.Fail(request.Info, Convert(request.Value))); } return(Result.Fail(request.Info, webData)); } var response = request.Value; paginationParameters.NextMaxId = response.Data.Cursor; while (!string.IsNullOrEmpty(paginationParameters.NextMaxId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextRequest = await GetRequest(CreateUri(paginationParameters?.NextMaxId)).ConfigureAwait(false); if (!nextRequest.Succeeded) { return(Result.Fail(nextRequest.Info, Convert(response))); } var nextResponse = nextRequest.Value; if (nextResponse.Data != null) { response.Data.Data.AddRange(nextResponse.Data.Data); } response.Data.Cursor = paginationParameters.NextMaxId = nextResponse.Data?.Cursor; paginationParameters.PagesLoaded++; } return(Result.Success(Convert(response))); } catch (HttpRequestException httpException) { logger?.LogError(httpException, "Error"); return(Result.Fail(httpException, webData, ResponseType.NetworkProblem)); } catch (Exception exception) { logger?.LogError(exception, "Error"); return(Result.Fail(exception, webData)); } }
/// <summary> /// Get self account follow requests /// </summary> /// <param name="paginationParameters">Pagination parameters: next id and max amount of pages to load</param> public async Task <IResult <InstaWebTextData> > GetFollowRequestsAsync(PaginationParameters paginationParameters) { InstaUserAuthValidator.Validate(userAuthValidate); var textDataList = new InstaWebTextData(); try { if (paginationParameters == null) { paginationParameters = PaginationParameters.MaxPagesToLoad(1); } InstaWebTextData Convert(InstaWebSettingsPageResponse settingsPageResponse) { return(InstaConvertersFabric.Instance.GetWebTextDataListConverter(settingsPageResponse).Convert()); } Uri CreateUri(string cursor = null) { return(InstaWebUriCreator.GetCurrentFollowRequestsUri(cursor)); } var request = await GetRequest(CreateUri(paginationParameters?.NextMaxId)).ConfigureAwait(false); if (!request.Succeeded) { if (request.Value != null) { return(Result.Fail(request.Info, Convert(request.Value))); } return(Result.Fail(request.Info, textDataList)); } var response = request.Value; paginationParameters.NextMaxId = response.Data.Cursor; while (!string.IsNullOrEmpty(paginationParameters.NextMaxId) && paginationParameters.PagesLoaded < paginationParameters.MaximumPagesToLoad) { var nextRequest = await GetRequest(CreateUri(paginationParameters?.NextMaxId)).ConfigureAwait(false); if (!nextRequest.Succeeded) { return(Result.Fail(nextRequest.Info, Convert(response))); } var nextResponse = nextRequest.Value; if (nextResponse.Data != null) { response.Data.Data.AddRange(nextResponse.Data.Data); } response.Data.Cursor = paginationParameters.NextMaxId = nextResponse.Data?.Cursor; paginationParameters.PagesLoaded++; } return(Result.Success(Convert(response))); } catch (HttpRequestException httpException) { logger?.LogError(httpException, "Error"); return(Result.Fail(httpException, textDataList, ResponseType.NetworkProblem)); } catch (Exception exception) { logger?.LogError(exception, "Error"); return(Result.Fail(exception, textDataList)); } }