如何使用 JavaScript SDK 获取 Facebook 用户的好友信息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3324396/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get Facebook user's friends information using JavaScript SDK
提问by Nick
I am using the Facebook JavaScript SDK. I am able to get the user's information using:
我正在使用 Facebook JavaScript SDK。我能够使用以下方法获取用户信息:
FB.api('/me', function(response) {
....
});
I get the user's friends using:
我让用户的朋友使用:
FB.api('/me/friends', function(response) {
...
}); //.. it only has two values name and id.
I want to get friends Date of birth and location. Is there a FB.apimethod to get it or can I get it using FB.Data.query?
我想得到朋友的出生日期和地点。有没有FB.api办法获取它,或者我可以使用 FB.Data.query 获取它吗?
回答by jches
First your app needs to have the correct permissions, friends_birthdayand friends_locationin this case.
首先您的应用需要有正确的权限,friends_birthday而friends_location在这种情况下。
Next, use the fieldsparameter in your Graph API request to request the birthdayand locationfields:
接下来,使用fieldsGraph API 请求中的参数来请求birthday和location字段:
FB.api('/me/friends', {fields: 'name,id,location,birthday'}, function(response) {
//...
});
Depending on privacy settings on some of the friends' accounts, you may or may not be able to access birthday or location data, so make sure you handle the cases where the info is missing. See this questionfor why.
根据某些朋友帐户的隐私设置,您可能无法访问生日或位置数据,因此请确保处理信息丢失的情况。请参阅此问题以了解原因。
回答by Anton
Doing:
正在做:
FB.api('/me/friends', function(response) {
...
}); //.. it only has two values name and id.
You will get:
你会得到:
{data: [{id: "xxxxx", name: "Friend name"}, {id: "xxxxx", name: "Friend name"}]}
Than you could access the resource using received id:
您可以使用收到的 id 访问资源:
FB.api('/xxxxx', function(response) {
...
}); // {first_name: "Name", gender: "male", id: "xxxxxx",.. etc}
回答by daaku
You'll need an authenticated userwith the user_birthday, friends_birthday, user_location& friends_locationpermissions. Then you can do something like:
您需要一个具有, , &权限的经过身份验证的用户。然后你可以做这样的事情:user_birthdayfriends_birthdayuser_locationfriends_location
FB.api('/me/friends', { fields: 'name,id,location,birthday' }, function(result) {
// resut has the data
})
回答by Drupal Sinha
You can get complete friend's id and name in an array by using FB.api. One needs to initialize the app using FB.init and later checks if user is logged in using FB.getloginstatus(). then only FB.api is useful.
您可以使用 FB.api 在数组中获取完整的朋友的 id 和姓名。需要使用 FB.init 初始化应用程序,然后使用 FB.getloginstatus() 检查用户是否已登录。那么只有 FB.api 是有用的。
Here is a linkwhich explains how to fetch friends using Javascript SDK.
这是一个解释如何使用 Javascript SDK 获取朋友的链接。
回答by gideon
I barely know anything about FB API but have you looked at this:
http://developers.facebook.com/docs/reference/javascript/FB.Data.query
And this:
http://developers.facebook.com/docs/reference/fql/
我对 FB API 几乎一无所知,但你有没有看过这个:http:
//developers.facebook.com/docs/reference/javascript/FB.Data.query
而这个:http:
//developers.facebook.com/docs/参考/fql/

