PHP SDK 3.1.1 getUser() sometimes return 0

Phoxer Roberto Baglieri picture Phoxer Roberto Baglieri · Aug 29, 2011 · Viewed 11.7k times · Source

This is driving me crazy >=(

$facebook->getUser() works well sometimes, but sometimes returns 0

Here is my code: require 'fbapi/facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxx',
'secret' => 'xxxxx',
));
$user = $facebook->getUser();

the appId and secret are the correct ones.

Which could be the reason that getUser sometimes it returns 0???

Answer

Phillip picture Phillip · Aug 29, 2011

It's more than likely something on Facebook's end (devs have gone through this before a while back). If $user returns null or 0, simply reroute them to the login url (which you should have). The liklihood of it returning 0 again is minimal (unless there's a bug on their end or there's more to your code than what you've posted).