我正在尝试使用来自以下位置的示例代码来使用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()方法调用.
最佳答案 您可以使用以下方法代替使用Fetch().
Search search = listRequest.Execute();
fetch()api在版本1.4之后已被替换,但示例代码尚未更新.