3

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");
}
dfgd
  • 455
  • 1
  • 4
  • 20
  • 1
    part of this question too -> http://stackoverflow.com/questions/13821716/facebook-api-blank-response-and-no-exception, I guess is just a silent timeout, facebook responds with an empty page or something. – BG Adrian Feb 28 '13 at 20:51
  • Yes its true you can use try catch, and if response is null you can show user a custom error message to try again. – Muhammad Apr 23 '13 at 11:52

1 Answers1

1

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.

Antagonist
  • 612
  • 4
  • 17