José Joel.
José Joel.

Reputation: 2050

Can I use the Facebook graph api to get user's friends profiles pictures?

I'm new to facebook development, after testing the adobe api in a flash game I decided to test using the graph api communicating with my flash game. After doing basic stuff like connecting and getting my user's data, i was wondering if it's posible to get my user's friends profile pcitures, so i can pass them to UILoaders inside my flash game and show them.

If anyone can point me to examples of basic actions which use the facebook graph api, like invite friends or posting to the wall for example, that would be wonderful.

thanks.

update:

Using Nathan's suggestion I tried to get my friends and it worked:

$friends= $facebook->api('/me/friends?token='.$session['access_token']);
var_dump($friends);

Then I tried to get my friend's pictures with:

foreach ($friends['data'] as $friend)
    {
        $picture= $facebook->api('/'.$friend['id'].'/photo');
    }

But it didn't work. any idea ?

Thanks.

Upvotes: 10

Views: 35124

Answers (6)

alcaprar
alcaprar

Reputation: 787

I was looking for the same functionality and just noticed that it is not possible anymore (at the time of writing: 2019-11-17, api v5.0).

If you try to call /me/friends?fields=friends{name,id,profile_pic} you would receive an empty array of friends:

{
  "data": [
  ],
  "summary": {
    "total_count": 823
  }
}

Graph explorer shows this debug message: Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.

Upvotes: 1

Khalil Kitar
Khalil Kitar

Reputation: 341

I'm using http://facebook4j.org/en/code-examples.html and it's too simple.

example :

    System.out.println("picture of publisher : "+facebook.getPictureURL(feed.get(41).getFrom().getId()));

Upvotes: 0

Nate Totten
Nate Totten

Reputation: 8932

You first have to get the list of friends https://graph.facebook.com/me/friends?access_token=... then for each of the friends you can request http://graph.facebook.com/user_id/picture That will give you the url of their current profile photo.

Upvotes: 13

darki699
darki699

Reputation: 649

Easiest way yet was not posted here:

https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture

Upvotes: 64

Ahmed Ghoneim
Ahmed Ghoneim

Reputation: 7067

foreach ($friends['data'] as $friend)
    {
        $picture= $facebook->api('/'.$friend['id'].'/photo?token='.$session['access_token']);
    }

Upvotes: 0

UmutKa
UmutKa

Reputation: 759

It's not possible to get the photos this way : /'.$friend['id'].'/photo

Instead you have to loop through the albums first using : /'.$friend['id'].'/albums

Then for each album id you should use : /'.$album['id'].'/photos

This way you will reach the ID's of the pictures in that album. Then with the picture Id you had, you can get the photo /'.$picture['id'].'/picture

Hope this helps.

Upvotes: 1

Related Questions