您需要使用该应用程序access_token
,这可以通过执行以下操作在 Graph API Explorer 中进行测试:
- 转到访问令牌工具并复制您的应用程序
access_token
- 转到Graph API Explorer并从下拉列表中选择您的应用程序。
- 查询
APP_ID/accounts/test-users?access_token=app_access_token
这将检索测试用户
- 单击其中一个 ID(确保该用户与至少一个其他测试用户是朋友)并将查询更改为如下所示:
TEST_USER_ID/friends?fields=first_name,last_name,gender&access_token=app_access_token
- 你完成了!:-)
更新:
根据下面的评论,我尝试检索测试用户朋友的生日,但结果不一致。
- 使用测试用户的
access_token
:检索了 ID、生日和性别,但没有检索到姓名
- 使用应用程序
access_token
:检索了 ID、姓名和性别,但未检索生日
这是一个简单的代码:
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<head></head>
<body>
<div id="fb-root"></div>
<script>
// You can retrieve this from: https://developers.facebook.com/tools/access_token/
var app_access_token = "APP_ACCESS_TOKEN";
window.fbAsyncInit = function() {
FB.init({
appId : 'APP_ID_HERE', // App ID
channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
oauth : true, // enable OAuth 2.0
xfbml : true // parse XFBML
});
// Additional initialization code here
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
<table id="friends">
<tr>
<th>ID</th>
<th>Name</th>
<th>Gender</th>
<th>Birthday</th>
</tr>
</table>
<script>
function login(app) {
FB.login(function(response) {
if (response.authResponse) {
var obj = {fields: 'name,gender,birthday', limit: 500};
if(app)
obj.access_token = app_access_token;
FB.api('/'+response.authResponse.userID+'/friends', 'GET', obj, function(response) {
console.log(response);
if(response && response.data.length) {
var html = '';
for(var i=0; i<response.data.length; i++) {
html += "<tr>";
html += "<td>" + response.data[i].id + "</td>";
html += "<td>" + response.data[i].name + "</td>";
html += "<td>" + response.data[i].gender + "</td>";
html += "<td>" + response.data[i].birthday + "</td>";
html += "</tr>";
}
document.getElementById("friends").innerHTML += html;
}
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'user_birthday,friends_birthday'});
}
</script>
<button onclick="login();">List Friends With User Token</button>
<button onclick="login(1);">List Freinds With App Token</button>
</body>
</html>
使用我的一个测试用户帐户的结果:

前三行使用“ List Friends With User Token ”检索,其余行使用“ List Freinds With App Token ”检索。
最重要的是,这需要 Facebook 关注!