Get Facebook user pages list

Get facebook page using graph search which provide all pages which match the search text, but if you want to get page list of logged in user, than first generate token of that user, click here to know how to create token of facebook user

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


$user = $response->getDecodedBody();
foreach ($user['accounts']['data'] as $key => $value)
  'Page-id:'.$value['id'] . 'Page name:' .  $value['name']

Facebook did not return page data to logged in user if you did not set permission while generating the token. That permission display to user when he/she login using your app and if he/she give permission to your app then you able to get page data. How to set facebook permissions to get specifics data of users.


Was this post helpful?
Let us know if you liked the post. That’s the only way we can improve.
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.