PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, February 11, 2022

[FIXED] Get mutual_friends attending an Event on Facebook Graph API

 February 11, 2022     facebook-graph-api, facebook-php-sdk     No comments   

Issue

I have an event id and I want to get all mutual_friends attending an Events. Currently I just got and attending people from graph API. Like the following

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

But how I can filter mutual friends?


Solution

Yeah, now I finally got my own answer. As @We0 comment I try to get my own mutual friends and I try to got event attend list using event_id. And I merge with array_search function. And the following is my code...

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;
}


Answered By - Set Kyar Wa Lar
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing