我正在尝试使用Google自定义搜索API,使用Google API Ruby客户端。我已经通过Google API控制台设置了我的API密钥,并创建了我的CSE。根据文档,只要我提供API密钥(我正在这样做),就不需要OAuth2身份验证令牌来调用列表方法。但是,当我尝试执行下面的代码时,我收到以下错误:
参数错误:缺少访问令牌。
我错过了什么?这是我的代码:
# create client
client = Google::APIClient.new
# Fetch discovery doc
search = client.discovered_api('custom search')
# Call list method
response = client.execute(
search.cse.list, 'key' => '<my API key>', 'cx' => '<my CSE id>', 'alt' => 'json', 'q' => 'hello world'
)
client.authorization = nil
。这将告诉 Google 依赖 API 密钥而不是凭据。http://stackoverflow.com/a/10825773/838874 - Agent47DarkSoul