2

我正在尝试在使用 fb_graph(2.6.0) gem 创建内容时在 facebook 中分享,

我在尝试时遇到以下错误:

app = FbGraph::Application.new(APP_ID, :secret => APP_SECRET)
app.get_access_token
user = FbGraph::User.me(access_token).fetch

在开发控制台中

 => 377095675642525|X3SyfucEUnahEEFAFwkO_cFXRyc 
 1.9.3p194 :005 > user = FbGraph::User.me(access_token).fetch
 LoadError: cannot load such file -- {"error":{"message":"An active access token must be used to query information about the current user.","type":"OAuthException","code":2500}}
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in `load'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in `block in load'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in `block in load_dependency'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:640:in `new_constants_in'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:223:in `load_dependency'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/activesupport-3.1.10/lib/active_support/dependencies.rb:234:in `load'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/fb_graph-2.6.0/lib/fb_graph/node.rb:138:in `handle_response'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/fb_graph-2.6.0/lib/fb_graph/node.rb:49:in `get'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/fb_graph-2.6.0/lib/fb_graph/node.rb:19:in `fetch'
from (irb):5
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.10/lib/rails/commands/console.rb:45:in `start'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.10/lib/rails/commands/console.rb:8:in `start'
from /home/love/.rvm/gems/ruby-1.9.3-p194/gems/railties-3.1.10/lib/rails/commands.rb:40:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

在 Heroku 日志中:

 Started GET "/facebook/callback?code=AQDccVXzo55GpSCCnr0vXKb2xpHFtJ8E_Eb-3AfA6Wcx5G1QEMHr4vNuH0366tGYVFepTuDZv2Z9_BLeXdMRNcLtfg1N3mz8rbTZowblEeGqg9Ls7R7X7P2GiuyFPJa0PTric7gjE8cZ3olRyP27otiGfzWQ4REoqS-BFsH4BwyfyZSiZxoQ0PPDUmlxeve4Cn9qAKzC2sYmEEbdTcPo2quu" for 122.164.241.1 at 2013-02-26 05:42:55 +0000
2013-02-26T05:42:56+00:00 app[web.1]: #<FbGraph::Auth:0x00000004e1bbb8 @client=#   <Rack::OAuth2::Client:0x00000004e19b38 @identifier=188451457933295, @secret="13d6158a6ebe35a115bcae7f0ec14826", @redirect_uri=nil, @scheme=nil, @host="graph.facebook.com", @port=nil, @authorization_endpoint="/oauth/authorize", @token_endpoint="/oauth/access_token", @grant=#  <Rack::OAuth2::Client::Grant::ClientCredentials:0x00000005484e28>>>
app/controllers/facebooks_controller.rb:29:in `create'
2013-02-26T05:42:56+00:00 heroku[router]: at=info method=GET path=/facebook/callback?code=AQDccVXzo55GpSCCnr0vXKb2xpHFtJ8E_Eb-3AfA6Wcx5G1QEMHr4vNuH0366tGYVFepTuDZv2Z9_BLeXdMRNcLtfg1N3mz8rbTZowblEeGqg9Ls7R7X7P2GiuyFPJa0PTric7gjE8cZ3olRyP27otiGfzWQ4REoqS-BFsH4BwyfyZSiZxoQ0PPDUmlxeve4Cn9qAKzC2sYmEEbdTcPo2quu host=x.y.com fwd="122.164.241.1" dyno=web.1 queue=0 wait=0ms connect=2ms service=431ms status=500 bytes=0

在facebook中单击登录后,我在浏览器中出现以下错误,

Server error
The website encountered an error while retrieving     http://x.y.com/facebook/callback?code=AQAGIeV8GLZWMI98eauog2eTDq7jeXBEhBSDg3izqBBjS6mVN3y5tgTSGcagmAqMTYHyB_EJArN834cglLjBL4yHDQHlEaD7j7wSmSPN43hZXQhCHJTbvP0HHJPBwAiNCCZYOiP2jpLLAyznLoufwvN-6p6dLgjup8WPtRyEeUspv94m-O5lC146JHNvWFUvCHaPaQ2wPWyfmh5C89mR2G0R#_=_. It may be down for maintenance or configured incorrectly.
4

1 回答 1

0

从您的问题来看,您似乎正在使用应用程序访问令牌来访问用户信息。这取决于

FbGraph::InvalidRequest: OAuthException :: An active access token must be used to query information about the current user.

而您应该使用用户的访问令牌来获取个人资料信息或在墙上发布。

如果您尝试使用 Facebook 进行omniauth 登录,这里有一个很好的入门教程http://blog.yangtheman.com/2012/02/09/facebook-connect-with-rails-omniauth-devise/

使用fb_graph时,您应该拥有用户的访问令牌来执行任何进一步的操作,例如更新状态(墙帖)

这需要一个访问令牌,您应该在为该用户验证您的应用程序时保存该令牌。

你可以做

me = FbGraph::User.me(ACCESS_TOKEN)
me.feed!(
  :message => 'Updating via FbGraph',
  :picture => 'https://graph.facebook.com/matake/picture',
  :link => 'https://github.com/nov/fb_graph',
  :name => 'FbGraph',
  :description => 'A Ruby wrapper for Facebook Graph API'
)

注意:这将需要您可以在范围属性中指定的扩展权限

Rails.application.config.middleware.use OmniAuth::Builder do
  # The following is for facebook
  provider :facebook, [APP ID], [SECRET KEY], {:scope =&gt; 'email, read_stream, read_friendlists, friends_likes, friends_status, offline_access'}

  # If you want to also configure for additional login services, they would be configured here.
end
于 2013-02-26T09:06:17.663 回答