user1173169
user1173169

Reputation:

Get the facebook User name using the API

i'm trying to get the facebook user name using the API

this is my code:

$facebook = new Facebook(array(
  'appId'  => $this->app_id,
  'secret' => $this->app_secret,
  'cookie' => true,
));



$session = $facebook->getUser();

$me = null;
if ($session) {
    try {
        $uid = $facebook->getUser();
        echo $uid;
        exit();
        $me = $facebook->api('/me');
        echo $me;
        exit();
    } catch (FacebookApiException $e) {
        error_log($e);
    }
    $personLastName= $me['last_name'];

    var_dump($personLastName);
    exit();

the line where it crashes:

$me = $facebook->api('/me');

No errors displayed, just white page and no log error in apache

Some help would be welcome! Thanks in advance

Upvotes: 0

Views: 96

Answers (1)

Toretto
Toretto

Reputation: 4711

You are try to print the first element and then you have terminate the statement with exit; then the rest of the code will not be executed.Try this

$me = null;
if ($session) {
    try {
        $uid = $facebook->getUser();
        echo $uid;

        $me = $facebook->api('/me');
        echo $me;

    } catch (FacebookApiException $e) {
        error_log($e);
    }
    $personLastName= $me['last_name'];

    var_dump($personLastName);
    exit();
}

Upvotes: 1

Related Questions