简体   繁体   中英

FbGraph OAuthException Invalid OAuth access token

I am using FbGraph in my Ruby on Rails app along with Omniauth. I am using the server-side method to get the long-term (60 day) access token for the user and then storing it in a session variable. When trying to access the API in the following code:

token = session[:facebook_token]

user = FbGraph::User.me(token)
user = user.fetch

I get OAuthException :: Invalid OAuth access token . However when I add puts token and copy the printed token into the Facebook Graph API Explorer (online tool) I have no issues and the token is reported as valid ... I can even make the API call that's failing through FbGraph.

I was using the short term tokens from the JavaScript SDK (2 hour) and the same code was working fine so something about the move to the long term token is screwing everything up.

How are you setting session[:facebook_token] in the first place? It sounds like either a character encoding issue or perhaps even simply extra whitespace.

Why don't you try user = FbGraph::User.me(token.strip)

Also, you can update (extend) the access token itself like this: https://github.com/nov/fb_graph#extend-access-token-lifetime

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM