How to get Facebook user detail with PHP SDK

To get Facebook user detail we have to authenticate the user with Facebook and user token than we make request to facebook graph API to get user details.

try {
  // Returns a `Facebook\FacebookResponse` object
1  $response = $fb->get('/me?fields=id,name', 'User_Access_token');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage(); 
  exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}

 

$user = $response->getDecodedBody();
$user->id;

 

See: How to create Access token of Facebook user

Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
Yes0
No0
Harinder Singh

Harinder Singh

My name is Harinder Singh and I specialize in Software industry. I consider myself as a life learner. I love learning new concepts, embracing new ideas and reading and searching for innovation.