/// <summary> /// Get users (short) who liked certain media. Normaly it return around 1000 last users. /// </summary> /// <param name="mediaId">Media id</param> public async Task <IResult <InstaLikersList> > GetMediaLikersAsync(string mediaId) { UserAuthValidator.Validate(_userAuthValidate); try { var likers = new InstaLikersList(); var likersUri = UriCreator.GetMediaLikersUri(mediaId); var request = HttpHelper.GetDefaultRequest(HttpMethod.Get, likersUri, _deviceInfo); var response = await _httpRequestProcessor.SendAsync(request); var json = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaLikersList>(response, json)); } var mediaLikersResponse = JsonConvert.DeserializeObject <InstaMediaLikersResponse>(json); likers.UsersCount = mediaLikersResponse.UsersCount; if (mediaLikersResponse.UsersCount < 1) { return(Result.Success(likers)); } likers.AddRange( mediaLikersResponse.Users.Select(ConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); return(Result.Success(likers)); } catch (Exception exception) { _logger?.LogException(exception); return(Result.Fail <InstaLikersList>(exception)); } }
/// <summary> /// Get media comments likers /// </summary> /// <param name="mediaId">Media id</param> public async Task <IResult <InstaLikersList> > GetMediaCommentLikersAsync(string mediaId) { InstaUserAuthValidator.Validate(userAuthValidate); try { var instaUri = InstaUriCreator.GetMediaCommetLikersUri(mediaId); var request = httpHelper.GetDefaultRequest(HttpMethod.Get, instaUri, deviceInfo); var response = await httpRequestProcessor.SendAsync(request).ConfigureAwait(false); var json = await response.Content.ReadAsStringAsync().ConfigureAwait(false); if (response.StatusCode != HttpStatusCode.OK) { return(Result.UnExpectedResponse <InstaLikersList>(response, json)); } var likers = new InstaLikersList(); var likersResponse = JsonConvert.DeserializeObject <InstaMediaLikersResponse>(json); likers.UsersCount = likersResponse.UsersCount; likers.AddRange( likersResponse.Users.Select(InstaConvertersFabric.Instance.GetUserShortConverter) .Select(converter => converter.Convert())); return(Result.Success(likers)); } catch (HttpRequestException httpException) { logger?.LogError(httpException, "Error"); return(Result.Fail(httpException, default(InstaLikersList), ResponseType.NetworkProblem)); } catch (Exception exception) { logger?.LogError(exception, "Error"); return(Result.Fail <InstaLikersList>(exception)); } }