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

岁酱吖の 提交于 2019-12-24 00:35:47

问题


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 .?


回答1:


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/




回答2:


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




回答3:


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"
    }
  ]
}



回答4:


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



来源:https://stackoverflow.com/questions/9001033/how-can-i-get-the-admins-user-id-of-a-page-in-facebook

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!