retrieve Profile ID for Facebook Page Owner/Admin

11,976

Solution 1

After September 22, 2011, manage_pages permission is required to do that. You must request for the manage_pages permission, get the page access_token and then make the admins request with the page access_token.

Please refer to http://developers.facebook.com/docs/reference/api/permissions/ for updated permissions.

Solution 2

Well, I actually had the same problem some time back and found a solution for it. What i was doing was passing the user access token intead of the page access token. I would suggest that you should try something like

$pageIds=$facebook->api('/me/accounts');
$pageAccessToken=$pageIds["data"][1]["access_token"]; //get the access token for page "[1]" over here  

and then try

facebook->api('/<page id>/admins', 'get' , array("access_token" => $pageAccessToken));
Share:
11,976
willemaw
Author by

willemaw

Updated on June 04, 2022

Comments

  • willemaw
    willemaw almost 2 years

    In a previous version of the PHP SDK there was the ability in an App to get the Profile ID of the user that owned the page where the app was installed.

    $facebook->get_profile_user()
    

    This was possible without having the end user authorize access to the Facebook App.

    However I can't find anything similar in the new JS or Graph API's. The closest thing I could find was the https://graph.facebook.com/<page_id>/admins, however it seems this call either doesn't work, or requires addition permissions:

    Access Token:AAADF5PRI7BkBAKSz9Wqfbkuib6JH7WkZCQDZBgLNO10s1ZAMKF7BO7Y3YCVqkYNuCJ9QroWHYYn8n5wC8diPuBDPGsNUS5tDnZAZA6rFSx28VtpvVhUlY
    Graph API: /210093142392039/admins
    $this->facebook->api('/291231207559006/admins')
    
    ( ! ) Fatal error: Uncaught OAuthException: (#210) Subject must be a page. thrown in /html/classes/facebook/base_facebook.php on line 1033
    

    Is this functionality gone? We were using the Profile ID as a key in a datasource, so it'd be ideal to keep this same key, if not we can start storing the page-id instead, however this would the users would have to reinitialize the app..

  • willemaw
    willemaw over 12 years
    Doesn't the user still need to grant the app access for this to work since you're going after /me/accounts? I'm getting 'need active access token for user' exception..
  • Rahul Thakur
    Rahul Thakur over 12 years
    Thats right you need a "manage_pages" permission for that. Well now that it is giving a "need active access token for user" exception i would suggest that you go through this article http://stackoverflow.com/questions/2687770/do-facebook-oauth‌​-2-0-access-tokens-e‌​xpire. Not sure but i hope it is of some help.
  • willemaw
    willemaw over 12 years
    Thanks for the info, I don't think this is a solvable problem anymore in this aspect. My solution is going to be to grab the PageID from the SignedRequest and use that as the key and if the AdminId is needed relate the two together at signup time, rather than some time later.
  • Rahul Thakur
    Rahul Thakur over 12 years
    I checked the graph api explorer, with the above code, and was able to get the admins or owners of the page. So its working for sure. There must be something wrong with the access token... well i am just guessing. Hey why dont you try it out on the graph api explorer itself and try to find out there if something's wrong.