2

How can i get the admins user id of a page in facebook using grapg API .?

For eg: This will give the details of page KFC

https://graph.facebook.com/126380033352

{
  "id": "126380033352",
  "name": "I Love KFC",
  "picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/50510_126380033352_4943708_s.jpg",
  "link": "http://www.facebook.com/Official.KFC",
  "likes": 543485,
  "category": "Food/beverages",
  "username": "Official.KFC",
  "founded": "1929",
  "about": "KFC United Kingdom. Finger Lickin' Good.",
  "can_post": true,
  "talking_about_count": 8965,
  "type": "page"
}

I need to get the user id of the page admin..? I have checked the permissions but i dont know how to get that .?

Sarath
  • 9,030
  • 11
  • 51
  • 84

4 Answers4

5

First: User must be a admin of that page.

With "manage_pages" permission, request GET https://graph.facebook.com/[PAGE_ID]?fields=access_token In response will get a Page admin access_token. Now use the page admin access_token to request GET https://graph.facebook.com/[PAGE_ID]/admins

In response you will get the list of admins, their id and usernames.

Reference: http://developers.facebook.com/docs/reference/api/page/

Sarim
  • 3,124
  • 2
  • 20
  • 20
0

You cannot get all admin users of the app but you can test any uid.

Firstly you need to grant 'manage_pages' permission then query page_admin table. FQL implementation for current user looks as following:

$isAdmin = false;
$hasManagePerm = false;

try{
    $responses = $facebook->api('fql', 'GET', Array('q' => Array(
        'hasManagePerm' => 'SELECT manage_pages FROM permissions WHERE uid=me()',
        'isAdmin' => 'SELECT 1 FROM page_admin WHERE uid=me() AND page_id=' . APP_FB_ID,
    )));
    foreach ((Array)$responses['data'] as $response) {
        if($response['name'] == 'hasManagePerm') {
            $hasManagePerm = !empty($response['fql_result_set'][0]['manage_pages']);
        } else if($response['name'] == 'isAdmin') {
            $isAdmin = !empty($response['fql_result_set']);
        }
    }
} catch (Exception $ex) {

}

if(empty($hasManagePerm)) {
    throw new AdminPanelAccessRestrictedException("perm");
}

if(empty($isAdmin)) {
    throw new AdminPanelAccessRestrictedException("admin");
}

WHERE APP_FB_ID - an application id

Oleg Tsiupka
  • 136
  • 5
0

If you don't like the Graph objects, you can always use FQL

fql?q=SELECT uid, page_id, type FROM page_admin WHERE page_id = {pageId}

returns this:

{
  "data": [
    {
      "uid": "6905135096",
      "page_id": "{pageId}",
      "type": "ATHLETE"
    },
    {
      "uid": "14408356540",
      "page_id": "{pageId}",
      "type": "ATHLETE"
    },
    {
      "uid": "51936644133",
      "page_id": "{pageId}",
      "type": "ATHLETE"
    },
    {
      "uid": "7230226073",
      "page_id": "{pageId}",
      "type": "ATHLETE"
    }
  ]
}
DMCS
  • 31,720
  • 14
  • 71
  • 104
-1

@Sarim's link of '/admins' is deprecated after Graph API 2.1.
FB Graph API 2.2 and above use '/roles'

Mike Lapinskas
  • 149
  • 2
  • 5