Search code examples
facebookfacebook-graph-apifacebook-php-sdk

trying to determine if user is a page admin using FB GraphAPI


I have a page tab app. When the user clicks on the "Go to App" and is sent to my page tab edit url i am trying to determine if they are a page admin or not. I have tried two different methods. I have tried from the only admin/owner of the page method 1 used from https://developers.facebook.com/blog/post/2011/09/05/platform-updates--labor-day-edition/

 $page_info = $facebook->api("/".$pageID."?fields=access_token");
 $pageAccessToken = $page_info['access_token']     

 $is_admin_url = "https://graph.facebook.com/" . $pageID 
  . "/admins/" . $FBuser . "?access_token=" 
  . $pageAccessToken;

$response = file_get_contents($is_admin_url);

response is {"data":[]}

I have also tried::

path = '/'.$pageID.'/admins/'.$FBuser;
$params = array(
        'app_id' => FB_APP_ID,
        'access_token' => $pageAccessToken
);
$is_admin = $facebook->api($path, 'POST', $params);

Solution

  • Although PAGE_ID/admins is a valid request, you need an admin's access_token to see the list. I.e. only admins can see who else is an admin.

    What you can do is approach this from the other end by yielding a list of pages that the user is an admin of (using the https://graph.facebook.com/USER_ID/accounts/ data and the manage_pages permission) and search through that list for your application.

    However, I would understand if some users would be reluctant to give the manage_pages permission, as it also provides an access token to authenticate as that page, which would be something of a security hole on their part. Unfortunately, there does not seem to be another way to access a list of pages for which that user is an admin.