gpt4 book ai didi

ruby - open_http: 403 禁止 (OpenURI::HTTPError)

转载 作者:数据小太阳 更新时间:2023-10-29 07:19:50 25 4
gpt4 key购买 nike

我正在尝试使用以下脚本从我的 Google+ API 中提取数据:

require 'open-uri'
require 'json'

google_api_key = 'put your google api key here'
page_id = '105672627985088123672'

data = open("https://www.googleapis.com/plus/v1/people/#{page_id}?key=#{google_api_key}").read
obj = JSON.parse(data)

puts obj['plusOneCount'].to_i

但是,我一直收到这个错误:

/Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:346:in `open_http': 403 Forbidden (OpenURI::HTTPError)
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:769:in `buffer_open'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:203:in `block in open_loop'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:201:in `catch'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:201:in `open_loop'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:146:in `open_uri'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:671:in `open'
from /Users/xng/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/open-uri.rb:33:in `open'
from gplus.rb:8:in `<main>'

我不确定这里出了什么问题,任何帮助都会很棒。

最佳答案

问题看起来是您的 google API key 与 google 在其服务器中拥有的 key 不匹配。因此,您需要确保您使用的是正确的 key 。它是私有(private)服务还是免费服务?

关于ruby - open_http: 403 禁止 (OpenURI::HTTPError),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20735648/

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