我正试图从Facebook获得一个人的共同朋友。我使用以下教程中的代码的变体。
https://www.youtube.com/watch?v=TcABLvN6Fmk
并尝试使用以下信息
https://developers.facebook.com/docs/graph-api/reference/v2.6/user.context/mutual_friends
我几乎得到了它的工作我的问题是,我无法弄清楚如何表达查询
这是我的代码
require "fbsdk/src/Facebook/autoload.php";
$fb = new Facebook\Facebook([
'app_id' => 'MY_APP_ID',
'app_secret' => 'MY_APP_SECRET',
'default_graph_version' => 'v2.6'
]);
if(isset($_SESSION['user_profile']['facebook_access_token'])){
$query = ‘/me/friends?limit=100’;
$res = $fb->get($query, $_SESSION['user_profile']['facebook_access_token']);
$my_friend_list = $res->getGraphEdge()->asArray();
echo "my friends that use the app:<br/>";
print_r($my_friend_list);
echo "<br/><br/>";
if(isset($_SESSION['query']['user'][$current_user]['user_facebook_id'])){
$query = 'HAVE NO IDEA HOW TO PHRAZE THIS QUERY';
$res = $fb->get($query, $_SESSION['user_profile']['facebook_access_token']);
$mutual_friend_list = $res->getGraphEdge()->asArray();
echo "mutual friends that use the app:<br/>";
print_r($mutual_friend_list);
echo "<br/><br/>";
}
}
答案 0 :(得分:1)
相互朋友意味着您想要了解两个用户之间的相互关系。如文档中所述,调用是
GET /v2.6/{user-id}?fields=context.fields{mutual_friends}
其中{user-id}
是您想要检查共同朋友的用户ID。基本用户来自您通过呼叫使用的用户访问令牌。
请注意,两位用户都需要{0}}授予您的应用!
答案 1 :(得分:0)
成功!感谢Tobi我有一个解决方案。我已经抽象了一点,所以它对其他人有用。确保您拥有5.0 SDK
https://developers.facebook.com/docs/php/gettingstarted#install-manually
require "fbsdk/src/Facebook/autoload.php";
$fb = new Facebook\Facebook([
'app_id' => 'MY_APP_ID',
'app_secret' => 'MY_APP_SECRET',
'default_graph_version' => 'v2.5'
]);
$my_friend_list = array();
$mutual_friend_list = array();
if(isset($your_access_token)){
$query = '/me/friends?limit=100';
$res = $fb->get($your_access_token);
$my_friend_list = $res->getGraphEdge()->asArray();
if(isset($another_user_id)){
$query = '/'.$another_user_id.'?fields=context.fields%28mutual_friends%29';
$res = $fb->get($your_access_token);
$mutual_friend_list = $res->getGraphObject()->asArray();
}
}
//process information of $my_friend_list
//process information of $mutual_friend_list
//both of these have extra info in the array so check their structure