让mutual_friends参加Facebook Graph API上的活动

时间:2014-10-16 07:23:16

标签: facebook-graph-api facebook-php-sdk

我有一个event id,我想让所有的mutual_friends参加活动。目前我刚刚从图API中获得并参加了人们。如下所示

https://graph.facebook.com/v2.1/event-id/?fields=attending

但我如何过滤共同的朋友?

1 个答案:

答案 0 :(得分:2)

是的,现在我终于得到了自己的答案。正如@ We0评论我试图找到我自己的共同朋友,我尝试使用event_id获得事件参加名单。我与array_search函数合并。以下是我的代码......

function getCommonFriend($event_id)
{
    //Setup Facebook Configuration
    $facebook                   = new Facebook(Config::get('facebook'));

    //If there is no common friends so there will be 0
    $commmon_friends = 0;

    //Get Attending Friends
    $event_attending            = $facebook->api('v2.1/' .$event_id . '?fields=attending');
    $event_attending_friends    = $event_attending['attending']['data'];

    $events_attending_friends_id = array();

    foreach ($event_attending_friends as $key => $value) {
        $events_attending_friends_id['id']{$key} = $value['id'];
    }

    //Get Own Mutual Friends
    $me                         = $facebook->api('v2.1/me?fields=context');
    $my_mutual_friends          = $me['context']['mutual_friends']['data'];

    foreach ($my_mutual_friends as $key => $value) {
        $my_mutual_friends_id = $value['id'];
        $get_commmon_friends = array_search($my_mutual_friends_id, $events_attending_friends_id['id']);
        if (!empty($get_commmon_friends)) {
            $commmon_friends ++;
        }
    }



    return $commmon_friends;
}