[英]FbGraph OAuthException Invalid OAuth access token
I am using FbGraph in my Ruby on Rails app along with Omniauth. 我在我的Ruby on Rails应用程序中使用FbGraph以及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. 我使用服务器端方法为用户获取长期(60天)访问令牌,然后将其存储在会话变量中。 When trying to access the API in the following code: 尝试访问以下代码中的API时:
token = session[:facebook_token]
user = FbGraph::User.me(token)
user = user.fetch
I get OAuthException :: Invalid OAuth access token
. 我收到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. 然而,当我添加puts token
并将打印的令牌复制到Facebook Graph API Explorer(在线工具)时,我没有任何问题,并且令牌被报告为有效...我甚至可以通过FbGraph使API调用失败。
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. 我正在使用JavaScript SDK中的短期令牌(2小时),并且相同的代码工作正常,所以关于转移到长期令牌的一些事情是搞砸了一切。
How are you setting session[:facebook_token]
in the first place? 你是如何设置session[:facebook_token]
的? 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)
为什么不尝试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 此外,您可以像这样更新(扩展)访问令牌: https : //github.com/nov/fb_graph#extend-access-token-lifetime
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.