How To Get The Pages The Facebook User is Admin Of

Some times you need the Facebook pages of a user. You can get it by simple fql. Here is how

// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => FACEBOOK_APP_ID,
  'secret' => FACEBOOK_SECRET_KEY,
  'cookie' => false,
));

$user = $facebook->getUser();

$loginUrl   = $facebook->getLoginUrl(
            array(
                'scope'         => 'offline_access,email,manage_pages'
            )
    );
	
if ($user) {
  try {
        // Proceed knowing you have a logged in user who's authenticated.
       $user_profile = $facebook->api('/me');;	
	$user_pages = $facebook->api(array('method' => 'fql.query','query' => 'SELECT page_id,page_url,name,pic_square FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid ='.$user.' )'   ));		
  } catch (FacebookApiException $e) {
    $user = null;
  }
}	

if (!$user or $chk==1) {
	echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
}

$user_pages will have the information about the pages that the user admin of. See this code in this post

About Zakir Hyder

This entry was written by .

15. July 2011 by Zakir Hyder
Categories: Facebook, Graph Api, PHP, Social Networking Application Development | Tags: , , , , | Comments

Comments

  1. […] Uploading a Video to Facebook User’s wall or Page’s wall Saturday, July 16, 2011 1:27 AM How To Get The Pages The Facebook User is Admin Of […]