public async Task <IEnumerable <Geocode> > GetGeocodesForAddress(string address) { GoogleApiRequest request = new GoogleApiRequestBuilder().ToApi(GeocodeApiUri).WithQueryParam("address", address).Build(); GoogleApiResponse response = await this.client.Get(request); return(response.ConvertResults <Geocode>()); }
public string GetUploadPlaylist(string channel) { var json = Raw.GetChannelDetails(new YouTubeChannelPartsCollection(YouTubeChannelPart.ContentDetails), channel); var obj = JsonObject.ParseJson(json); if (obj == null) { return(null); } // Check for any API errors GoogleApiResponse.ValidateResponse(obj); // Get the items list and parse it var items = obj.GetArray("items"); if (items == null || items.Length < 1) { return(null); } var details = items.GetObject(0).GetObject("contentDetails"); if (details == null) { return(null); } var relatedPlaylists = details.GetObject("relatedPlaylists"); if (relatedPlaylists == null) { return(null); } return(relatedPlaylists.GetString("uploads")); }
private async Task <IEnumerable <Place> > GetPlacesNearCoordinateWithPageToken(double latitude, double longitude, double radiusMeters, string pageToken) { string locationArgument = $"{latitude},{longitude}"; GoogleApiRequestBuilder requestBuilder = new GoogleApiRequestBuilder() .ToApi(PlaceApiUri) .ToSubApi(NearbySearchSubApiUri) .WithQueryParam("location", locationArgument) .WithQueryParam("radius", radiusMeters.ToString()); if (pageToken != null) { requestBuilder = requestBuilder.WithQueryParam("pagetoken", pageToken); } GoogleApiRequest request = requestBuilder.Build(); GoogleApiResponse response = await this.client.Get(request); IEnumerable <Place> places = response.ConvertResults <Place>(); if (!string.IsNullOrEmpty(response.NextPageToken)) { await Task.Delay(2000); // I've found that you have to wait a little bit to get the next page. Otherwise, it gives back an "invalid request" response. places = places.Concat(await GetPlacesNearCoordinateWithPageToken(latitude, longitude, radiusMeters, response.NextPageToken)); } return(places); }
public async Task <IEnumerable <Geocode> > GetGeocodesForCoordinate(double latitude, double longitude) { string latlngArgument = $"{latitude},{longitude}"; GoogleApiRequest request = new GoogleApiRequestBuilder().ToApi(GeocodeApiUri).WithQueryParam("latlng", latlngArgument).Build(); GoogleApiResponse response = await this.client.Get(request); return(response.ConvertResults <Geocode>()); }
public SearchEngineMatch MapFromGoogleSearchEngineResponse(GoogleApiResponse entity) { return(new SearchEngineMatch { SearchEngineId = (int)SearchEngineTypeEnums.Google, SearchEngineName = SearchEngineTypeEnums.Google.ToString(), NumberMatches = entity?.SearchInformation?.TotalResults }); }
public GoogleApiResponse Search(string searchValue) { var request = new RestRequest($"https://www.googleapis.com/customsearch/v1", Method.GET); request.AddQueryParameter("key", _configuration["ApiKeys:GoogleApiKey"]); request.AddQueryParameter("cx", _configuration["ApiKeys:GoogleCx"]); request.AddQueryParameter("q", searchValue); var response = Execute <GoogleApiResponse>(request); var result = new GoogleApiResponse(); if (response.StatusCode == System.Net.HttpStatusCode.OK) { result = response.Data; } else { _logger.LogRequestError(request, response); } return(result); }
public static async Task <GoogleApiResponse <PlaylistItem> > IncludeStatistics(this GoogleApiResponse <PlaylistItem> playlistItems) { if (playlistItems != null && playlistItems.Items.Count > 0) { foreach (var playlistItem in playlistItems.Items) { if (playlistItem.VideoDetail.ResourceIdentifier != null) { var videoId = ((VideoIdentifier)(object)playlistItem.VideoDetail.ResourceIdentifier).VideoId; var requestUrl = RequestUri.GetRequestUrl(Base.GoogleApis, Api.Youtube, ApiVersion.V3, Endpoint.Videos); #region Set Parameters var parameters = new Dictionary <string, string>() { { "key", Credentials.ApiKey }, { "part", Part.Statistics.GetDescription() }, { "id", ((VideoIdentifier)(object)playlistItem.VideoDetail.ResourceIdentifier).VideoId } }; #endregion requestUrl = requestUrl.Append(parameters); var response = await HttpHelper.Instance.GetAsync(requestUrl); if (!string.IsNullOrWhiteSpace(response)) { var statistic = JsonConvert.DeserializeObject <GoogleApiResponse <Video <string> > >(response); if (statistic != null && statistic.Items?.Count > 0) { playlistItem.RelatedVideoStatistics = statistic.Items.FirstOrDefault().Statistics; } } } } } return(playlistItems); }