2016-06-10 27 views
0

我正在使用Google.Apis.Customsearch.v1来定制谷歌搜索。查询需要numstart参数用于分页。按照谷歌的文档herestartnum查询参数谷歌搜索API抛出错误,有效参数

开始

可选。 start参数表示应该包含在搜索结果中的第一个匹配结果。 start参数使用从零开始的索引,意思是第一个结果是0,第二个结果是1等等。

start参数与num参数一起使用以确定要返回哪些搜索结果。请注意,任何查询都不会返回超过1000个结果,即使超过1000个文档与查询匹配,因此将开始设置为1000或更多时也不会产生结果。

NUM

说明
可选。 num参数标识要返回的搜索结果的数量。

默认的num值是10,最大值是20.如果您请求的结果超过20个,则只返回20个结果。

注意:如果搜索结果的总数小于请求的结果数量,则会返回所有可用的搜索结果。

然而,当我设置start为0,num 20我得到错误

{“Google.Apis.Requests.RequestError \ r \ n无效的值[400] \ r \ n错误[\ r \ n \ tMessage [无效值]地址[ - ]原因[无效]域[全球] \ r \ n] \ r \ n“}

这里是我的代码

 CustomsearchService customSearchService = 
      new CustomsearchService(new Google.Apis.Services.BaseClientService.Initializer() { ApiKey = apiKey }); 
    Google.Apis.Customsearch.v1.CseResource.ListRequest listRequest = customSearchService.Cse.List(query); 
    listRequest.Cx = searchengineid;    
    listRequest.Start = 0; 
    listRequest.Num = 20; 
    Search search = listRequest.Execute(); 

我必须将start设置为1,将num设置为10才能使其工作。那么,为什么它不工作按文档

回答

0

你报的资源是XML API参考:

这页是指自定义搜索API的XML版本,这是 仅适用于谷歌网站搜索顾客。

我认为你正在使用的库是JSON/Atom API

https://developers.google.com/custom-search/json-api/v1/reference/cse/list

据我所知零不是为start参数有效值和num参数是有点不同JSON/Atom API。

num无符号整数) - 的搜索结果数返回。有效值是1到10之间的整数,包括1和10。

https://developers.google.com/custom-search/json-api/v1/reference/cse/list#num