$ Facebook-> api ('/ me'); sometimes does not load

I have a problem with. $ user_profile = $ facebook-> api ('/ me'); Sometimes it works and sometimes it doesn't.

8 out of 10 cases it works and suddenly I have an empty string in $ user_profile. Where is the magic?

(I have the newest PHP SDK installed)

// FB lib
require_once './libs/facebook.php';
error_reporting(0);

// connect
$facebook = new Facebook(array(  
    'appId'  => 'xxx',  
    'secret' => 'xxx',  
    'cookie' => true
)); 

$user = $facebook->getUser();
$fb_id = $facebook->getUser();

if ($user) {
    try {
        $_SESSION['user'] = $user_profile = $facebook->api('/me');
        $_SESSION['fb_id'] = $fb_id;
} catch (FacebookApiException $e) {
    error_log($e);
    $user = NULL;
  }
}

if ($user == NULL) {
   $loginUrl = $facebook->getLoginUrl(
       array(
        'display' => 'popup',
        'scope' => 'publish_stream, user_likes',
        'redirect_url' => 'https://xxxx.cz/xxxx/canvas/index.php'
    )
);    
} else {  
     $_SESSION['fb_id'] = $fb_id;
     header("Location: https://xxxx.cz/xxxx/xxxx.php");
}

      

+3


source to share


1 answer


The magic comes from Facebook, their platform seems unstable, you are dependent on your servers which may not always work.



I know you are expecting a solution, but there is really only an answer to explain why it is not working.

+1


source







All Articles