gpt4 book ai didi

Ruby HTTP 库获取与 Facebook 应用程序的连接重置

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

以下 curl 命令按预期工作:
curl 'https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=myappid&client_secret=myclientsecret'

我想在我的 Ruby 程序中做同样的事情。下面的代码给我一个错误:

fb_access_token_url = URI.parse(                                             
'https://graph.facebook.com/oauth/access_token' +
'?grant_type=client_credentials' +
'&client_id=' + FACEBOOK_APP_ID +
'&client_secret=' + FACEBOOK_APP_SECRET)
fb_access_token = Net::HTTP.get(fb_access_token_url)

这段代码也是如此:

fb_access_token_host = 'graph.facebook.com'                                  
fb_access_token_path_and_params = (
'/oauth/access_token' +
'?grant_type=client_credentials' +
'&client_id=' + FACEBOOK_APP_ID +
'&client_secret=' + FACEBOOK_APP_SECRET)
https_port = Net::HTTP.https_default_port()

fb_access_token = Net::HTTP.get_response(fb_access_token_host,
fb_access_token_path_and_params,
https_port)

错误如下:

Errno::ECONNRESET: Connection reset by peer
/usr/lib/ruby/1.8/net/protocol.rb:135:in `sysread'
/usr/lib/ruby/1.8/net/protocol.rb:135:in `rbuf_fill'
/usr/lib/ruby/1.8/timeout.rb:67:in `timeout'
/usr/lib/ruby/1.8/timeout.rb:101:in `timeout'
/usr/lib/ruby/1.8/net/protocol.rb:134:in `rbuf_fill'
/usr/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/usr/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/usr/lib/ruby/1.8/net/http.rb:2028:in `read_status_line'
/usr/lib/ruby/1.8/net/http.rb:2017:in `read_new'
/usr/lib/ruby/1.8/net/http.rb:1051:in `request'
/usr/lib/ruby/1.8/net/http.rb:948:in `request_get'
/usr/lib/ruby/1.8/net/http.rb:380:in `get_response'
/usr/lib/ruby/1.8/net/http.rb:543:in `start'
/usr/lib/ruby/1.8/net/http.rb:379:in `get_response'
/usr/lib/ruby/1.8/net/http.rb:356:in `get'
./test-login-and-registration.rb:182:in `test_facebook_register'

我在 Ubuntu 12.04 上使用 Ruby 1.8.7

最佳答案

感谢 Manoj Awasthi 让我意识到有些 ssl 方法我无法使用。

问题是我需要 net/http 而不是 net/https。

工作片段:

fb_access_token_url = URI.parse(                                             
'https://graph.facebook.com/oauth/access_token' +
'?grant_type=client_credentials' +
'&client_id=' + FACEBOOK_APP_ID +
'&client_secret=' + FACEBOOK_APP_SECRET)
https = Net::HTTP.new(fb_access_token_url.host, fb_access_token_url.port)
https.use_ssl = true
https.verify_mode = OpenSSL::SSL::VERIFY_NONE
fb_access_token = https.request_get(fb_access_token_url.path + '?' +
fb_access_token_url.query)

关于Ruby HTTP 库获取与 Facebook 应用程序的连接重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11369234/

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