views:

50

answers:

2

I am trying to get a list of mutual friends of myself and another user but none of the API I found in the documentation works. Either I get some weird permission errors that I can only get my friends list and no other user or I get the following error:

Fatal error: Call to a member function friends_getMutualFriends() on a non-object in /home/app.php on line 27 

Is there a standard way that is used to get the total number of mutual friends or at least the list of friend ids of my friend?

A: 

Well it's actually friends.getMutualFriends().

Have a play here.

Marko
@Marko: That gives me the same error. I'm trying: `$mutual_friends = $facebook->api_client->friends_getMutualFriends(xxx,yyy);` where xxx is my id... Am I doing something wrong? Or could you give me a small example? The playground in the URL you pointed to gives me this error: `This API call could not be completed due to resource limits",`
Legend
Why are you using an underscore rather than a dot? friends**.**getMutualFriends
Marko
@Marko: I tried the other one too... I get the same error: `Fatal error: Call to a member function getMutualFriends() on a non-object in /home/app.php on line 27`. I included the `facebook.php` file that I downloaded from the website.
Legend
Which API are you using? The old REST or Graph?
Marko
@Marko: Hmm... Guess its the graphs API... So can this be done using this new API? I am not sure if I want to include both the old and new libraries...
Legend
@Legend: You're right others seem to be having the same issue.
Marko
@Marko: Oh boy so do you suggest that I revert back to the old one? Or is there a hack to just get the number using the old lib without actually using it as the main library? I cannot include both because it will then give me class redeclaration errors... Any suggestions?
Legend
@Legend the new PHP SDK supports both the graph and rest api.
Nathan Totten
@Nathan: Oh... Would you be kind enough to give me an example on how to do this using the new SDK?
Legend
Here is a good tutorial that will show you: http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/
Nathan Totten
@Nathan Totten: Thanks a lot... I will go through it...
Legend
A: 

Ok... This one gave me a real hard time. I managed to do this using the Facebook JS SDK. Here's the snippet just in case anyone else wants to do this:

    FB.api(
          {
            method: 'fql.query',
            query: 'SELECT id FROM profile WHERE id IN (SELECT uid2 FROM friend WHERE uid1=me())'
          },
          function(response) {
            $.each(response, function(json) {
                console.info(response[json].id);
                        FB.api(
                          {
                            method: 'friends.getMutualFriends',
                            target_uid: 'INSERT ANOTHER FRIEND ID HERE'
                          },
                          function(response) {
                            console.info(response);
                          }
                          );
                return false;
            });

          }
        );
Legend