我试图用Google自定义搜索引擎API来结束一个相当基本的搜索。我面临的问题是,我唯一能得到的结果显然是前10名:
module WalterSobchak
class GoogleCustomSearch
def initialize
@client = Google::APIClient.new(
key: configatron.google.api_key, authorization: nil)
@search = @client.discovered_api('customsearch')
end
def query(q, num)
@client.execute(api_method: @search.cse.list,
parameters: {q: q, startIndex: num,
key: configatron.google.api_key,
cx: configatron.google.custom_search_engine})
end
end
end这段代码很简单,但工作得很好:首先,我使用我的api_key初始化我的GCS客户机,然后我可以用我喜欢的任何参数调用它,例如:
client.query('poker', 10)使用字符串“扑克”搜索我的自定义引擎,并从结果集的第10个元素开始。我的问题是,它不工作,我总是得到相同的结果,我会得到我将获得的startIndex选项。问题可能是,我不知道该参数是否以这种方式命名,或者它是否是我可以使用的正确参数:我尝试过startIndex、start、start_index、num (这个方法有效,但最大值为10,我需要至少30个结果),有时该参数被拒绝,有时不会产生任何效果。
以前有没有人做过这样的事,能帮我吗?
发布于 2014-02-18 17:43:57
来自API:https://developers.google.com/apis-explorer/#p/customsearch/v1/search.cse.list
看起来,您要查找的参数是“start”:返回的第一个结果的索引(整数)。另一个参数(num)是返回的结果数。
您可以在资源管理器上手动尝试,并查看它为什么不返回所需的内容。
https://stackoverflow.com/questions/21857686
复制相似问题