如何使用JavaScript SDK获取Facebook用户的朋友的信息 [英] How to get Facebook user's friends information using JavaScript SDK
问题描述
我正在使用Facebook JavaScript SDK。我可以使用以下方式获取用户信息:
I am using the Facebook JavaScript SDK. I am able to get the user's information using:
FB.api('/me', function(response) {
....
});
我得到用户的朋友:
FB.api('/me/friends', function(response) {
...
}); //.. it only has two values name and id.
我想得到朋友出生日期和位置。有没有一个 FB.api
方法来获取它,或者可以使用FB.Data.query获取它?
I want to get friends Date of birth and location. Is there a FB.api
method to get it or can I get it using FB.Data.query?
推荐答案
首先,您的应用需要具有正确的权限, friends_birthday
和 friends_location
在这种情况下。
First your app needs to have the correct permissions, friends_birthday
and friends_location
in this case.
接下来,使用Graph API请求中的字段
参数请求生日
和 location
fields:
Next, use the fields
parameter in your Graph API request to request the birthday
and location
fields:
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 question for why.
这篇关于如何使用JavaScript SDK获取Facebook用户的朋友的信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!