我一直在尝试使用脸谱图api,虽然ruby在打开api url时会引发EOFError(https://graph.facebook.com / .....) 我正在使用Ruby 1.8.6和Rails 2.2.2。 代码如下:
require 'uri'
require 'https'
access_token = open("https://graph.facebook.com/oauth/access_token?client_id=app_id&client_secret=app_secret&grant_type=client_credentials"){|f|
f.read
}
出现以下错误:
end of file reached
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `sysread'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:133:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:62:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/timeout.rb:93:in `timeout'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:132:in `rbuf_fill'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:116:in `readuntil'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/protocol.rb:126:in `readline'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2022:in `read_status_line'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:2011:in `read_new'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:1050:in `request'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:248:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/net/http.rb:543:in `start'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:242:in `open_http'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:616:in `buffer_open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:164:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `catch'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:162:in `open_loop'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:132:in `open_uri'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:518:in `open'
/Users/user/.rvm/rubies/ruby-1.8.6-p420/lib/ruby/1.8/open-uri.rb:30:in `open'
app/models/news_release.rb:75:in `post_to_facebook_wall'
我彻底用谷歌搜索并搜索了这个错误并尝试了诸如httpparty,机制,fb_graph和考拉。 然而,那些提出相同的efoerror。 似乎ruby-1.8.6或open-uri存在错误,但我不想升级ruby。
有什么想法吗? 提前谢谢。
答案 0 :(得分:0)
看起来ssl失败了,因为你没有填写参数。试试这样:
require 'open-uri'
app_id = 'fill_me_out'
app_secret = 'fill_me_out_too'
url = "https://graph.facebook.com/oauth/access_token?client_id=#{app_id}&client_secret=#{app_secret}&grant_type=client_credentials"
access_token = open(url).read