duanli9591 2014-12-14 18:16
浏览 41
已采纳

Facebook令牌无效但可以访问api

I have a token from facebook (from the graph explorer tool). I am using the PHP sdk. I created a session using the said token and called the FacebookSession::validate() method. It returned TRUE. I uploaded it in a test server and when I run it it says Session has expired. I debugged the token and the expiry should last 2 months.

When I try getting the user info (in the test server) it also works. Even the session info. It only throws a "session has expired" exception when I call the validate() method. Any ideas what I am doing wrong? Take note that this only happened after I uploaded it on a live server. The code on my local server and live are the same.

Here is a sample code. The appid and secret are already set by calling the setDefaultApplication() method.

<?php

\Facebook\FacebookSession::setDefaultApplication('app-id','app-secret');
$s = new \Facebook\FacebookSession('my-access-token');
$u = null;
try {
    $fbr = new \Facebook\FacebookRequest($s, 'GET', '/1663246619?fields=id,first_name,last_name,gender,email,birthday,bio');
    $u = $fbr->execute();
    $i = $s->getSessionInfo();
    var_dump($i->getProperty('is_valid'));
    var_dump($s->validate());
} catch(\Exception $e) {
    var_dump($e->getMessage());
}

var_dump($u->getGraphObject()->asArray());

Here is the response

bool(true)

string(50) "Session has expired, or is not valid for this app."

array(11) {
  ["id"]=>
  string(10) "1663246619"
  ["email"]=>
  string(22) "my-email@email.com"
  ["first_name"]=>
  string(12) "Kapitanluffy"
  ["gender"]=>
  string(6) "female"
  ["last_name"]=>
  string(6) "Pirata"
  ["link"]=>
  string(34) "http://www.facebook.com/1663246619"
  ["locale"]=>
  string(5) "en_US"
  ["name"]=>
  string(19) "Kapitanluffy Pirata"
  ["timezone"]=>
  int(8)
  ["updated_time"]=>
  string(24) "2014-12-06T23:47:48+0000"
  ["verified"]=>
  bool(true)
}

other notes:

  • The access token is for my app
  • I am using facebook-php-sdk-v4 version 4.0.3

展开全部

  • 写回答

1条回答 默认 最新

  • dprntkxh703029 2014-12-15 09:27
    关注

    You need to upgrade your SDK version to the latest stable version 4.0.12. There have been a whole lot of bug fixes and security updates since 4.0.3. One such bug is related to the session info validation that you're having trouble with. That should hopefully fix your issue. :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部