Iamは、Railsアプリケーションでfb_graphを使用して、Facebookで認証されている場合にアクセストークンを取得および設定します。ユーザーが友達を招待するために認証する必要があるInvitesコントローラーがあります。私のコードは次のようになります:
def facebook
if params[:code]
set_oauth_token(params[:code])
elsif params[:error]
redirect_to landing_path, :alert => "Access Denied"
return
end
if current_user.oauth_token.nil?
redirect_to client.authorization_uri(
:scope => "user_about_me, email, publish_stream, user_location, user_interests, user_birthday, user_likes, user_hometown, offline_access"
)
end
private
def set_oauth_token(token)
client.authorization_code = params[:code]
access_token = client.access_token! :client_auth_body
user = FbGraph::User.me(access_token).fetch
current_user.oauth_token = access_token
current_user.save(:validate => false)
end
def client
FbGraph::Auth.new(ENV["FACEBOOK_KEY"], ENV["FACEBOOK_SECRET"], :redirect_uri => invites_facebook_url).client
end
しかし、Iamはエラーを受け取ります:
FbGraph::InvalidRequest at /invites/facebook
OAuthException :: An active access token must be used to query information about the current user.
エラーは次の行にあります。
user = FbGraph::User.me(access_token).fetch
解決策を探してコードを変更しようとしましたが、それでも問題を解決できませんでした。そのすべてのoauthトークンは無効です。
解決策を見つけるのを手伝ってください。どうもありがとう!!