OAuth令牌停止工作时该怎么办?

时间:2011-09-19 00:59:00

标签: facebook

我正在使用图谱API为Facebook选择“fan of the week”的应用,并自动将其发布到自己的Feed中。

为了在Feed上宣布粉丝,我会为安装该应用的用户存储OAuth访问令牌。但是,有时令牌会失效,然后应用程序将无法发布到Feed。

{
   "error" : {
      "message" : "Error validating access token: The session has been invalidated 
      because the user has changed the password.",
      "type" : "OAuthException"
   }
}

以下是我有时会遇到的另一种错误:

{
    "error": {
        "message": "Error validating access token: Session does not match 
        current stored session. This may be because the user changed the 
        password since the time the session was created or Facebook has changed 
        the session for security reasons.",
        "type": "OAuthException"
    }
}

我已经为这些用户提供了“offline_access”,但有时令牌仍然无效。还有什么我可以做的,以防止这种情况发生,除了向用户发送电子邮件,要求他们再次访问应用程序页面,以便我可以获得一个新的OAuth令牌?

2 个答案:

答案 0 :(得分:0)

没有办法解决这个问题,不需要用户介入。如果它是一个应用程序或页面用户不太可能经常访问,那么发送该电子邮件听起来是个好主意。当用户访问页面或应用程序时,您可以使用FB Javascript SDK自动刷新会话,并使用更新数据库中令牌的处理程序订阅FB.Event.subscribe('auth.sessionChange')。

答案 1 :(得分:0)

如果您尝试发布到用户Feed并且您拥有尚未撤消的publish_stream权限,则您很可能仍然使用以下格式的access_token发布到/ userId / feed:appid | appsecret。请注意,/我显然不会工作,因为您正在使用应用程序访问令牌。