简体   繁体   English

FbGraph OAuthException无效的OAuth访问令牌

[英]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.

相关问题 Unsplash API OAuth 错误:访问令牌无效 - Unsplash API OAuth error: The access token is invalid 得到# - Getting #<FbGraph::InvalidRequest: OAuthException :: Unknown path components: 如何使用fbgraph获取需要访问令牌的字段 - How to fetch fields that require access token using fbgraph omn​​iauth OAuthException&OAuth ::未经授权 - omniauth OAuthException & OAuth::Unauthorized AuthenticationError.OAUTH_TOKEN_INVALID - AuthenticationError.OAUTH_TOKEN_INVALID (#803)您请求的某些别名不存在:access_token“,” type”:“ OAuthException” - (#803) Some of the aliases you requested do not exist: access_token“,”type“:”OAuthException" 与FbGraph循环的多桩帖子给出:OAuthException ::(#1)创建共享时发生错误 - Multipule posts in loop with FbGraph gives: OAuthException :: (#1) An error occured while creating the share 我该如何解决FbGraph :: Unauthorized:OAuthException ::(#200)用户尚未授权应用程序执行此操作 - How do i solve FbGraph::Unauthorized: OAuthException :: (#200) The user hasn't authorized the application to perform this action 访问令牌无效(Zoom API) - Invalid access token (Zoom API) 尝试两次使用同一令牌时,Oauth令牌无效吗? - Oauth token invalid when trying to use the same token twice?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM