gpt4 book ai didi

ruby-on-rails - Google-api-client 请求访问 token

转载 作者:太空宇宙 更新时间:2023-11-03 17:08:12 24 4
gpt4 key购买 nike

我的要求是获得 google.com 中搜索查询的前 20 个链接。我正在使用 Google-api-client !对于 ruby 。

这是我正在使用的代码,

require 'google/api_client'
client = Google::APIClient.new
response = client.execute(
search.cse.list, 'key' => '<My Key>', 'cx' => '013036536707430787589%3A_pqjad5hr1a', 'alt' => 'json', 'q' => 'hello world'
)

现在我面临三个问题,

  1. 我想使用默认的 Google 搜索,那么“cx”值应该是多少?我使用的一个来自 https://developers.google.com/custom-search/v1/using_rest#cx
  2. 我没有得到任何结果,而是收到以下警告“ArgumentError:缺少访问 token 。”我通过定义 "client.authorization.access_token = '123'"使用虚拟 token 解决了这个问题。但我不确定它是否是正确的解决方案。
  3. 在我定义 access_token 之后,我仍然没有得到任何结果。而是收到警告“无效凭据”。但是如果我使用相同的 URL(由 api 生成),在浏览器中我会得到结果。

最佳答案

不是设置虚拟访问 token ,而是将授权机制设置为 nil:

client.authorization = nil

这样它就不会发送授权 header ,只会依赖 API key 来识别您的应用。

关于ruby-on-rails - Google-api-client 请求访问 token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10811804/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com