Facebook API , recover first name

Asked

Viewed 269 times

0

I am using version 2.9 of the Facebook Api in PHP, my goal is to recover the most basic information.

From what I read in the documentation, the only authorization I would need is the email address, which I already have. First Name and Last Name would not require additional authorization

But when executing

$loader = require __DIR__ . '\..\vendor\autoload.php';
    $token = $_POST['token'];
    include './Facebook/Facebook.php';
    $fb = new \Facebook\Facebook([
        'app_id' => 'meu id aqui',
        'app_secret' => 'meu segredo aqui',
        'default_graph_version' => 'v2.9',
        'default_access_token' => $token
    ]);

    $helper = $fb->getRedirectLoginHelper();

    $response = $fb->get('/me',$token);
    $me = $response->getGraphUser();
    echo json_encode(array(
        "resultado" => true, 
        "id" => $me->getId(),
        "name" => $me->getName(), 
        "fields" => $me->getFieldNames(),
        "email" => $me->getEmail(),
        "cover" => $me->getField("cover"),
        "firstname" => $me->getFirstName(),
        "lastname"=>$me->getLastName(),
        "picture" => $me->getPicture()

));

I just get

  1. id
  2. name
  3. email

All other fields are null

When passing through parameter no get('/me?fields=email,name,id,lastname,firstname'), PHP sends the error

Graph returned an error: (#100) Tried accessing nonexisting field (lastname) on Node type (User)*

How to recover this information with the API?

1 answer

2


  • It worked properly, thank you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.