Facebook access_token 为空

发布于 2024-11-24 01:46:08 字数 1017 浏览 3 评论 0原文

我正在尝试获取好友列表,但收到此错误:

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /server/url/base_facebook.php on line 970

这是我正在使用的代码:

$facebook = new Facebook(array(
  'appId'  => $appID,
  'secret' => $appSecret,
  'cookie' => true, // enable optional cookie support
));
$result = $facebook->api('/me/friends/',array('access_token' => $facebook->access_token));

这是我在 $facebook 变量中返回的数据:

 Facebook Object
(
    [appId:protected] => 220........
    [apiSecret:protected] => 2162e6c1b771......
    [user:protected] => 
    [signedRequest:protected] => 
    [state:protected] => 894ad3b36c2ebdcbcf6d4f110641dd4f
    [accessToken:protected] => 
    [fileUploadSupport:protected] => 
)

由于某种原因,access_token 为空。 本来好好的,突然就停了…… 该应用程序已经拥有权限,并且我正在使用最新的 PHP SDK v3.0.1

请帮助我...我对这个问题快疯了...

谢谢, 酒吧。

I'm trying to get friends list and I get this error:

Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in /server/url/base_facebook.php on line 970

This is the code I'm using:

$facebook = new Facebook(array(
  'appId'  => $appID,
  'secret' => $appSecret,
  'cookie' => true, // enable optional cookie support
));
$result = $facebook->api('/me/friends/',array('access_token' => $facebook->access_token));

Here's the data I get back in the $facebook variable:

 Facebook Object
(
    [appId:protected] => 220........
    [apiSecret:protected] => 2162e6c1b771......
    [user:protected] => 
    [signedRequest:protected] => 
    [state:protected] => 894ad3b36c2ebdcbcf6d4f110641dd4f
    [accessToken:protected] => 
    [fileUploadSupport:protected] => 
)

For some reason the access_token is empty.
It worked fine and suddenly stopped...
The app already has the permissions and I'm using the latest PHP SDK v3.0.1

Please help me... I'm going crazy with this issue...

Thanks,
Bar.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罪#恶を代价 2024-12-01 01:46:08

看来您需要首先解析签名的请求,这是 iframe 应用程序还是网站?

如果它是 iframe 应用程序并且用户已经授权,

请尝试此操作。

public function parse_signed_request($signed_request)
{

   list($encoded_sig, $payload) = explode('.', $signed_request, 2);

   $sig = $this->base64_url_decode($encoded_sig);
   $data = json_decode($this->base64_url_decode($payload), true);

   if(strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
       throw new Exception('bad algorithm');
   }

  $expected_sig = hash_hmac('sha256', $payload, $this->app_secret, $raw = true);

   if($sig !== $expected_sig) {
      throw new Exception('Bad signed JSON');
   }

  return $data;

}

这将解析签名的请求。

在你获得数据 var_dump 后,你将在其中看到 oauth_token....

 private function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
 }

it seems like u need to parse the signed request first is this an iframe app or a website?

if it's an iframe app and the user already authorized

try this.

public function parse_signed_request($signed_request)
{

   list($encoded_sig, $payload) = explode('.', $signed_request, 2);

   $sig = $this->base64_url_decode($encoded_sig);
   $data = json_decode($this->base64_url_decode($payload), true);

   if(strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
       throw new Exception('bad algorithm');
   }

  $expected_sig = hash_hmac('sha256', $payload, $this->app_secret, $raw = true);

   if($sig !== $expected_sig) {
      throw new Exception('Bad signed JSON');
   }

  return $data;

}

this will parse the signed request.

after u get the data var_dump it and in it u will see the oauth_token....

 private function base64_url_decode($input) {
    return base64_decode(strtr($input, '-_', '+/'));
 }
我纯我任性 2024-12-01 01:46:08

您应该在构造函数中添加 $this->load->library('facebook');

You should add $this->load->library('facebook'); in constructor .

ι不睡觉的鱼゛ 2024-12-01 01:46:08

您需要将 SDK 升级到 v3.0:

https://github.com/facebook/php-sdk< /a>

编辑:由于您使用的是 v.3.0,您的构造是错误的.. 构造函数不再有 $cookie 参数。我建议修改文档。

You need to upgrade your SDK to v3.0:

https://github.com/facebook/php-sdk

Edit: Since you are using v.3.0 your construct is wrong.. there is no more $cookie parameter for constructor. I suggest revising documentation.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文