18

我有一个存储用户访问令牌(以及其他一些数据)的数据库。当我授权用户时,我的权限列表包括 offline_access。

那么用户的访问令牌(客户端)是否总是与数据库中该用户的访问令牌相同?或者用户的访问令牌可以在他们注销、更改密码等时更改吗?

4

4 回答 4

22

No, the access token will not always be the same, even with offline_access. You will need to get a new access token when 1) the user changes their password or 2) deactivates your app. Otherwise, it should remain the same.

The users Facebook id will never change though. This can be parsed from the access token or obtained by calling the /me graph api.

Facebook has a blog post that goes on in detail about this.

Update: Facebook added a blog post specifically for handling revoked authorization.

于 2011-06-01T21:00:08.277 回答
5

只是想指出,offline_access 权限已被删除。

https://developers.facebook.com/roadmap/offline-access-removal/

“虽然我们正在通过开发者应用程序中的迁移设置删除offline_access 权限的使用,但我们现在允许选择使用具有长期过期时间的access_tokens,每次用户重新访问您的应用程序时都可以续订(请参阅以下例外)。”

通过更多搜索,您将找到如何扩展访问令牌。

自offline_access弃用以来如何延长访问令牌的有效性

这是来自https://stackoverflow.com/a/13224416/1753925的工作示例:

$facebook->setExtendedAccessToken();
$access_token = $_SESSION["fb_".$fb_appId."_access_token"];
// now set it into the facebook object ....
$facebook->setAccessToken($access_token);
// now our fb object will use the new token as usual ...
$accessToken = $facebook->getAccessToken();
于 2012-12-06T18:29:30.450 回答
2
 <?php
# We require the library
require("facebook.php");
require("db.php");
# Creating the facebook object
$facebook = new Facebook(array(
    'appId' => 'APP_ID',
    'secret' => 'APP_SECRET_ID',
    'cookie' => true
));
# Let's see if we have an active session
$session = $facebook->getSession();
if(!empty($session))
{
    try
    {
        $facebook_id = $session['uid'];
        $facebook_access_token=$session['access_token'];
        // Updating Facebook values into Users table
        mysql_query("UPDATE users SET facebook_uid='$facebook_id', facebook_access_token='$facebook_access_token' WHERE username='$user_session'");
        header("Location: http://yourwebsite.com/home.php");
    } 
    catch (Exception $e){}
}
else
{
    header("Location: http://yourwebsite.com/home.php");
}
于 2012-07-09T07:58:49.353 回答
1

不总是。

访问令牌通常会在某个时间点后过期。虽然有一种方法可以制作具有无限过期时间的访问令牌,但您需要请求offline_access作为权限之一。

在这里查看更多信息。

编辑刚刚看到您需要offline_access 作为权限。那么不,它们不会过期

于 2011-06-01T16:03:55.493 回答