0

I have this code in php that used to work, but now it doesn't, and even thoug it sounds like a lie, I did not touch anything!

$facebook = new Facebook(array(
  'appId'  => 'myApp',
  'secret' => 'mySecret',
  'cookie' => true ,
  'scope' => 'read_stream','manage_pages'
));


$user = $facebook->getUser();

if ($user!=0) {
   doStaff;
}else{
   $login_url = $facebook->getLoginUrl($params = array('scope' => "read_stream"));
   echo ("<script> top.location.href='".$login_url."'</script>");
}

The problem now is that gets stack in an infinite loop.

Any help would be really appreciate.

  • Read this: http://stackoverflow.com/questions/6790272/why-is-facebook-php-sdk-getuser-always-returning-0 – GBD Nov 30 '12 at 08:52

1 Answers1

0

You are probably using the deprecated Facebook PHP SDK. Try to get the latest Facebook PHP SDK

Stanley
  • 5,057
  • 4
  • 34
  • 44
  • But I downloaded it last month and it worked. Can that be possible? – Nahikari Otermin Nov 30 '12 at 10:22
  • Did `$facebook->getUser()` return valid user ID? If it returned 0, open `base_facebook.php`, go to `getUserFromAccessToken()` function and print out the exception. I was having this problem yesterday and found that the SDK I'm using is deprecated 4 months ago. – Stanley Nov 30 '12 at 10:31
  • Thank you so much. That was the problem. Anyway, I'd like to know how often do these change and if Facebook sends a message to let us know there is a new SDK. – Nahikari Otermin Nov 30 '12 at 11:24
  • I have no idea. I was also surprise that the function doesn't work. The `getUserFromAccessToken()` function should return the exception instead of just returning 0. – Stanley Nov 30 '12 at 15:08