c# – Google自定义搜索.NET API使用Fetch方法编译问题

我正在尝试使用来自以下位置的示例代码来使用Google CustomSearch API for .NET:

> Steps for using Google custom search API in .NET
> How can I do a search with Google Custom Search API for .NET?
> http://astrocoder.com/search-using-google-custom-search/

其中最简单的基本代码如下:

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();

但是,当我尝试编译它时,我收到以下错误:

'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

据我所知,我拥有所有必需的库文件(我使用NuGet来安装Google API).当我查看API文档时,我没有看到Fetch()方法,但是,我能够找到的所有示例代码都显示了listRequest.Fetch()方法调用.

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

最佳答案 您可以使用以下方法代替使用Fetch().

Search search = listRequest.Execute();

fetch()api在版本1.4之后已被替换,但示例代码尚未更新.

点赞