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

get user details from facebook api
facebook graph explorer
facebook graph api example
facebook graph api tutorial
facebook graph api /me
facebook graph api search
how to get facebook user details
facebook graph api limit

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.

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.

Graph API User, How do I use the Graph API to get profile pictures, user emails, friends lists, etc.? The app can then use the new User token to make Graph API requests, but can only access that specific User's photos, videos, and email address. This is an important attribute of access tokens. The app and User IDs are both encoded in the token itself (among other things), and we use those IDs to keep track of which data the User has permitted the app to access.

Easiest way yet was not posted here:

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

Overview - Graph API, Related Guides. Publishing using the Graph API GET /v7.0/me/feed HTTP/1.1 Host: graph.facebook.com /* PHP SDK Then your app can read: Timeline� The graph url actually will just redirect you to the url. I dont know much about flash, but if I wanted to use the photo of a user for example, I would do this: <img src=" graph.facebook.com/user_id/photo " /> So rather than making the $facebook->$api call just bind your photo to the url.

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.

Graph API User Accounts, For example, to publish the message “Hello” to a user's feed, you could make the Some Graph API endpoints can take parameters that are very large. developers.facebook.com Unfortunately, you cannot generate one of these that does not expire directly from the Graph API Explorer. To get one that never expires, you want a ‘Long-lived User Access

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.

FAQ - Graph API, After you've implemented one of our Facebook Login SDKs, you can use its methods to get an access token with your needed permission. If the User grants your� v7.0 The Graph API is the primary way for apps to read and write to the Facebook social graph. All of our SDKs and products interact with the Graph API in some way, and our other APIs are extensions of the Graph API, so understanding how the Graph API works is crucial.

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

User Feed - Graph API, You can do this if you are using Facebook connect by passing scope=email in the get string of your call to the Auth Dialog. I'd recommend using� The profile object is used within the Graph API to refer to the generic type that includes all of these other objects. The individual reference docs for each profile type should be used instead. Fields. When something has a profile, Graph API returns the fields for that object.

Advanced - Graph API, In this blog we go over some useful implementations of the Graph API that you can use to pull in user data as well as publish on your users behalf. Graph API Explorer GET /v7.0/ {user-id}/likes HTTP/1.1 Host: graph.facebook.com If you want to learn how to use the Graph API, read our Using Graph API guide.

Common Uses - Graph API, Graph API Explorer GET /v7.0/ {user-id}/accounts HTTP/1.1 Host: graph.facebook.com If you want to learn how to use the Graph API, read our Using Graph API guide.

Facebook Graph API, how to get users email?, You must be logged into Facebook in order to access the Graph API Explorer. You will also need to generate a user access token, which can be done directly in the Graph API Explorer. Once you've done these steps, you are ready to submit requests through the Graph API Explorer interface. Find more information about Graph API Explorer access token generation and request submissions in the Graph API Explorer documentation.

Comments
  • is this still possible with the updated graph api?
  • I had success getting my friends, but nothing with my friend's pictures. I updated the question to see if you could find the problem.
  • The problem is that getting the photo isnt an api call. The graph url actually will just redirect you to the url. I dont know much about flash, but if I wanted to use the photo of a user for example, I would do this: <img src="graph.facebook.com/user_id/photo" /> So rather than making the $facebook->$api call just bind your photo to the url.
  • Did you get this solved? If so, please consider marking my answer as the correct answer.
  • Maybe it's a difference between php and javascript (I'm still quite a noob with the facebook api) but to me it's not 'photo', but 'picture': graph.facebook.com/USER_ID/picture which will redirect to some other url (e.g. static.ak.fbcdn.net/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif)
  • It is indeed /picture
  • This is exactly what I was looking for. I don't know why it took so long to find it. Thank you.
  • +1 but i am getting small size of images. For this i need to again hit another service "graph.facebook.com/zuck/picture?width=100&height=100" can you merge both the query in once ?
  • This worked like a charm. just one question. It gives me a picture object like this: "picture": { "data": { "url": "fbcdn-profile-a.akamaihd.net....", "is_silhouette": false } } Is there a way to get url element directly ??
  • @Mangesh Get bigger pictures by doing a nested call, defining width(or height): https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture.width(400) or by type: https://graph.facebook.com/me/friends?access_token=[oauth_token]&fields=name,id,picture.type(large)