Question

I am attempting to use the Google CustomSearch API for .NET using sample code from the following locations:

The basic code in it's simplest form looks like:

string apiKey = "my-api-key";
string cseKey = "my-cse-id";
string query = "search query";
var bcsi = new BaseClientService.Initializer { ApiKey = apiKey };
var css = new CustomsearchService(bcsi);
var listRequest = css.Cse.List(query);
listRequest.Cx = cseKey;
Search search = listRequest.Fetch();

However, when I attempt to compile this, I am getting the following error:

'Google.Apis.Customsearch.v1.CseResource.ListRequest' does not 
contain a definition for 'Fetch' and no extension method 'Fetch' 
accepting a first argument of type 
'Google.Apis.Customsearch.v1.CseResource.ListRequest' could be found

As far as I can tell, I have all of the required library files (I used NuGet to install the Google APIs). When I view the API documentation, I do not see a Fetch() method, however, all of the sample code I have been able to find shows the listRequest.Fetch() method call.

https://developers.google.com/resources/api-libraries/documentation/customsearch/v1/csharp/latest/classGoogle_1_1Apis_1_1Customsearch_1_1v1_1_1CseResource_1_1ListRequest-members.html

Was it helpful?

Solution

Instead of using Fetch() you can use the following.

Search search = listRequest.Execute();

The fetch() api has been replaced after version 1.4 but the sample code has not been updated yet.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top