/// <summary> /// Get following hashtags information /// </summary> /// <param name="userId">User identifier (pk)</param> /// <returns> /// List of hashtags /// </returns> public async Task <IResult <InstaHashtagSearch> > GetFollowingHashtagsInfoAsync(long userId) { UserAuthValidator.Validate(_userAuthValidate); var tags = new InstaHashtagSearch(); try { var userUri = UriCreator.GetFollowingTagsInfoUri(userId); var request = _httpHelper.GetDefaultRequest(HttpMethod.Get, userUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaHashtagSearch>(response, json)); } var tagsResponse = JsonConvert.DeserializeObject <InstaHashtagSearchResponse>(json, new InstaHashtagSuggestedDataConverter()); tags = ConvertersFabric.Instance.GetHashTagsSearchConverter(tagsResponse).Convert(); return(Result.Success(tags)); } catch (HttpRequestException httpException) { _logger?.LogException(httpException); return(Result.Fail(httpException, default(InstaHashtagSearch), ResponseType.NetworkProblem)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, tags)); } }
/// <summary> /// Searches for specific hashtag by search query. /// </summary> /// <param name="query">Search query</param> /// <param name="excludeList">Array of numerical hashtag IDs (ie "17841562498105353") to exclude from the response, allowing you to skip tags from a previous call to get more results</param> /// <param name="rankToken">The rank token from the previous page's response</param> /// <returns> /// List of hashtags /// </returns> public async Task <IResult <InstaHashtagSearch> > SearchHashtagAsync(string query, IEnumerable <long> excludeList, string rankToken) { UserAuthValidator.Validate(_userAuthValidate); var RequestHeaderFieldsTooLarge = (HttpStatusCode)431; var count = 50; var tags = new InstaHashtagSearch(); try { var userUri = UriCreator.GetSearchTagUri(query, count, excludeList, rankToken); var request = _httpHelper.GetDefaultRequest(HttpMethod.Get, userUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode == RequestHeaderFieldsTooLarge) { return(Result.Success(tags)); } if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaHashtagSearch>(response, json)); } var tagsResponse = JsonConvert.DeserializeObject <InstaHashtagSearchResponse>(json, new InstaHashtagSearchDataConverter()); tags = ConvertersFabric.Instance.GetHashTagsSearchConverter(tagsResponse).Convert(); if (tags.Any() && excludeList != null && excludeList.Contains(tags.First().Id)) { tags.RemoveAt(0); } if (!tags.Any()) { tags = new InstaHashtagSearch(); } return(Result.Success(tags)); } catch (HttpRequestException httpException) { _logger?.LogException(httpException); return(Result.Fail(httpException, default(InstaHashtagSearch), ResponseType.NetworkProblem)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail(exception, tags)); } }