简体   繁体   中英

$facebook->api('/me'); sometimes doesn't load

I have problem with. $user_profile = $facebook->api('/me'); Sometimes it's working and sometimes it's not.

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

(I have the newest php SDK implemented)

// 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");
}

The magic comes from Facebook , their platform seems to be unstable , you are dependent from their servers which might not work always.

I know that you expect a solution , but really there is only answer to explain why it does not work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM