0

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) "[email protected]"
  ["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
4
  • are you using the token you took from Graph Explorer in your Application? Commented Dec 15, 2014 at 5:15
  • yes. i even revoked the permissions and re approved them Commented Dec 15, 2014 at 5:41
  • you cannot use the same token from Graph Explorer as it is tied to that specific application. You will have to generate an access_token from you application itself. Commented Dec 15, 2014 at 5:43
  • I meant the access_token I am using is the access token for my application. I changed the "Graph Explorer" application into my application. Commented Dec 15, 2014 at 5:45

1 Answer 1

0

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. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.