我已经设置了以下权限,包括我和应用的权限页面:
(注意“read_stream”)
<fb:login-button autologoutlink="true" perms="read_stream, user_about_me, user_likes, user_location, user_birthday, user_education_history, user_work_history, friends_about_me, friends_likes, friends_location, friends_birthday, friends_education_history, friends_work_history"></fb:login-button>
请求用户的个人资料非常有用:
FB.api('/me/friends', {
fields: "id,username,name,first_name,last_name,location,link,education,work,statuses.limit(1).fields(message)"
}, function(res){
console.log('FRIENDS', res.data);
});
但是,为用户的朋友获取相同内容不起作用。
它给出“500(内部服务器错误)”,facebook对象返回“未知错误”。
FB.api('/me/friends', {
fields: "id,username,name,first_name,last_name,location,link,education,work,statuses.limit(1).fields(message)"
}, function(res){
console.log('FRIENDS', res.data);
});
我已经将问题追溯到我要求的领域。部分statuses.limit(1).fields(message)
似乎是错误的来源,删除后/me/friends
会返回数据
但我不明白错误的原因。
/me
。read_steam
应该同时包含用户的状态和用户的朋友状态。我做错了什么或者是FB Graph API错误?
谢谢。
答案 0 :(得分:1)
这里试试这个:
$user = $facebook->getUser();
if ($user){
try {
$queries = array(
array('method' => 'GET', 'relative_url' => '/'.$user),
array('method' => 'GET', 'relative_url' => '/'.$user.'/friends', 'name' => 'get-friends'),
array('method' => 'GET','relative_url' => '?ids={result=get-friends:$.data.*.id}'),
);
// POST your queries to the batch endpoint on the graph.
try{
$batchResponse = $facebook->api('?batch='.json_encode($queries), 'POST');
}catch(Exception $o){
error_log($o);
}
}
catch (FacebookApiException $e) {
error_log($e); //Checks if user is logged out and generate an exception if access token is invalid
}
}
else{
$params = array(
'scope' => 'friends_birthday, friends_education_history, read_stream, read_friendlists, user_birthday, //Requesting User Permissions through Facebook App
'redirect_uri' => 'specify yours here' //User is redirected after Login
);
}
$user_details = json_decode($batchResponse[0]['body'], true);// User Own Info
$user_friends = json_decode($batchResponse[2]['body'], true);// User's Firend Info
你会得到一个数组对象。
或者你可以使用FQL,这里:
$friends = $facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT name, pic_big
FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = me())'
));
https://developers.facebook.com/docs/reference/fql/friend/
我正在做类似的事情,在这里:http://agbcorplegal.com/profile_filter/