在批量请求中获取Facebook用户信息?

时间:2011-08-08 10:42:03

标签: facebook-graph-api facebook

我可以使用以下https://graph.facebook.com/user_id来获取用户的数据(例如namegender等。)

有没有办法可以做类似的事情 https://graph.facebook.com/user1_id, user2_id, user3_id, ...? 所以我会在一个请求中获取所有数据?

2 个答案:

答案 0 :(得分:5)

是的,我尝试了以下行,它正在运行。

https://graph.facebook.com/?ids=19292868552,bharatpatil007,220439

它正在发挥作用。结果如下

{
   "19292868552": {
      "id": "19292868552",
      "name": "Facebook Platform",
      "picture": "http://profile.cc.fbcdn.net/hprofile-cc-ash2/211033_19292868552_7506301_s.jpg",
      "link": "http://www.facebook.com/platform",
      "likes": 2479998,
      "category": "Product/service",
      "website": "http://developers.facebook.com",
      "username": "platform",
      "founded": "May 2007",
      "company_overview": "Facebook Platform enables anyone to build social apps on Facebook and the web.",
      "mission": "To make the web more open and social."
   },
   "220439": {
      "id": "220439",
      "name": "Bret Taylor",
      "first_name": "Bret",
      "last_name": "Taylor",
      "link": "http://www.facebook.com/btaylor",
      "username": "btaylor",
      "gender": "male",
      "locale": "en_US"
   },
   "bharatpatil007": {
      "id": "793619474",
      "name": "Bharat Patil",
      "first_name": "Bharat",
      "last_name": "Patil",
      "link": "http://www.facebook.com/bharatpatil007",
      "username": "bharatpatil007",
      "gender": "male",
      "locale": "en_US"
   }
}

答案 1 :(得分:1)

假设你的评论 首先,您需要使用以下行[EDIT]

获取访问朋友信息的权限
$loginUrl = $facebook->getLoginUrl(
 array(
 'redirect_uri' =>'http://apps.facebook.com/yourappname/'
 ,'scope' => 'friends_about_me')
);

以下行会为您提供应用用户的朋友。

$friends = $facebook->api('/me/friends?access_token='.$accessToken.'&fields=id');

将这些ID压缩为以逗号分隔的字符串

$friends_ids;
foreach ($friends['data'] AS $friendsInfo)
{
  $friends_ids .= $friendsInfo['id'] .',';
}

删除最后一个逗号

$friends_ids = substr($friends_ids, 0, -1);

现在查询朋友的姓名和性别(以下行是您需要的)

$friends_info = $facebook->api('/?access_token='.$accessToken.'&fields=name,gender&ids='.$friends_ids);