如何在Facebook中获取页面的管理员用户ID。

时间:2012-01-25 10:23:00

标签: php facebook facebook-graph-api facebook-page

如何使用grapg API在facebook中获取网页的管理员用户ID。

例如:这将提供页面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"
}

我需要获取页面管理员的用户ID ..?我已经检查了权限,但我不知道如何获得。

4 个答案:

答案 0 :(得分:5)

首先:用户必须是该页面的管理员。

使用“manage_pages”权限,请求GET https://graph.facebook.com/[PAGE_ID]?fields=access_token 作为回应,将获得一个Page admin access_token。 现在使用页面admin access_token请求GET https://graph.facebook.com/[PAGE_ID]/admins

作为回应,您将获得管理员列表,他们的ID和用户名。

参考: http://developers.facebook.com/docs/reference/api/page/

答案 1 :(得分:0)

您无法获得应用的所有管理员用户,但您可以测试任何uid。

首先,您需要授予'manage_pages'权限,然后查询page_admin表。 当前用户的FQL实现如下所示:

$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 - 应用程序ID

答案 2 :(得分:0)

如果您不喜欢Graph对象,则可以始终使用FQL

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

返回:

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

答案 3 :(得分:-1)

@ Sarim的'/ admins'链接在Graph API 2.1之后已弃用 FB Graph API 2.2及更高版本使用'/ roles'