7

由于 Facebook 删除了 offline_access 权限,我遇到了麻烦。

尝试了 2 件事:

  1. 我正在按照 Facebook 的建议拨打电话。

    https://graph.facebook.com/oauth/access_token?             
        client_id=APP_ID&
        client_secret=APP_SECRET&
        grant_type=fb_exchange_token&
        fb_exchange_token=EXISTING_ACCESS_TOKEN 
    
  2. 我还尝试了 Android SDK,它使用意图来获取扩展的访问令牌:

    intent.setClassName("com.facebook.katana", "com.facebook.katana.platform.TokenRefreshService");
    

在developers.facebook.com,我将我的应用程序设置为“Native/Desktop”。

我也禁用了offline_access应用程序设置。

在尝试之前,我从我的 Facebook 帐户中删除了旧权限。

这两种方法都为我提供了 24 小时令牌。也许有人可以帮助我做出正确的决定以获得 60 天的令牌?

我看到了很多关于这个问题的错误报告,但他们也得到了解决。我的情况好像不是这样。

4

3 回答 3

1

使用以下函数获取扩展访问令牌: public function getExtendedAccessToken(){

try {
    // need to circumvent json_decode by calling _oauthRequest
      // directly, since response isn't JSON format.
    $access_token_response =
        $this->_oauthRequest(
            $this->getUrl('graph', '/oauth/access_token'),
            $params = array(    'client_id' => $this->getAppId(),
                                'client_secret' => $this->getApiSecret(),
                                'grant_type'=>'fb_exchange_token',
                                'fb_exchange_token'=>$this->getAccessToken(),
                          ));

} catch (FacebookApiException $e) {
  // most likely that user very recently revoked authorization.
  // In any event, we don't have an access token, so say so.
  return false;
}

if (empty($access_token_response)) {
  return false;
}

$response_params = array();
parse_str($access_token_response, $response_params);
if (!isset($response_params['access_token'])) {
  return false;
}

return $response_params['access_token'];

}

于 2012-07-11T07:47:35.487 回答
0

Assuming you are using the Facebook SDK, it allready has a method build in for exactly that.

facebook.extendAccessTokenIfNeeded(this, null);

this being the context and null being serviceListener.

You can use extendAccessToken as well, same principal

于 2012-05-28T15:53:33.420 回答
0

您是否测试过令牌是否持续超过 24 小时?根据文档,在某些情况下,仅更新过期时间,而令牌保持不变:

返回的 access_token 将有一个新的长寿命到期时间,但是,access_token 本身可能与之前授予的长寿命 access_token 相同,也可能不同。

于 2012-05-28T15:51:28.180 回答