Get Facebook user info in batch requests?
I can use the following https://graph.facebook.com/user_id
to get user's data (like name
, gender
etc.).
Is there a way I can do something similar to
http开发者_开发技巧s://graph.facebook.com/user1_id, user2_id, user3_id, ...
?
so I will get all the data in one request?
Yes, I tried following line and it is working.
https://graph.facebook.com/?ids=19292868552,bharatpatil007,220439
And it is working. It's result is as follows
{
"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"
}
}
Assuming your comment
First you will need to get the permissions to access friends info using following line [EDIT]
$loginUrl = $facebook->getLoginUrl(
array(
'redirect_uri' =>'http://apps.facebook.com/yourappname/'
,'scope' => 'friends_about_me')
);
Following line will give you friends of your app user.
$friends = $facebook->api('/me/friends?access_token='.$accessToken.'&fields=id');
condense those IDs into a comma-separated string
$friends_ids;
foreach ($friends['data'] AS $friendsInfo)
{
$friends_ids .= $friendsInfo['id'] .',';
}
remove last comma
$friends_ids = substr($friends_ids, 0, -1);
now query for friends' name and gender (Following line is what you needed)
$friends_info = $facebook->api('/?access_token='.$accessToken.'&fields=name,gender&ids='.$friends_ids);
精彩评论