Andy Hin
Andy Hin

Reputation: 31893

Facebook API: Get all profile pictures

What is the best way to get ALL profile pictures from a given user? What permissions do I need?

I know I can access the main profile pic using https://graph.facebook.com/[uid]/picture, but how do I get the entire album?

Upvotes: 24

Views: 41872

Answers (6)

Narayana Rao Routhu
Narayana Rao Routhu

Reputation: 6323

We will not get directly all profile pictures first we need fetch all albums using below URL

https://graph.facebook.com/v2.10/ 472802896428726/albums?access_token={access_token}&fields=id,name,cover_photo,count,from,type

Filter array using condition where type = profile and name = Profile Pictures then use album id to get photos using below URL

https://graph.facebook.com/v2.10/ 124683854573967/photos?access_token={access_token}&fields=id,source

Upvotes: 2

Aram Gevorgyan
Aram Gevorgyan

Reputation: 511

To get all profile pictures, firstly you need to get list of all albums, but if count of albums more than 24 you will not get the rest and you probably will not get profile photos album. For this you need to pass limit=0 to get albums URL.

Here is example code:

$tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=$yourAppId&redirect_uri=$yourRedirectUrl 
                &client_secret=$yourAppSecret&code={$_GET["code"]}";

$accessToken = file_get_contents($tokenUrl);

$extAlbumUrl = "https://graph.facebook.com/me/albums?$accessToken&limit=0";

$albums = json_decode(file_get_contents($extAlbumUrl)); 

Upvotes: 5

David Martinez
David Martinez

Reputation: 89

There is some way to get the albums of public users without any relation. For example, I'm not friend of the user "foo" but I want his photos. I can see his photos in the UI of Facebook but I can not get through the graph.

I'm using explorer from facebook with all permissions and I'm getting always an empty JSON. There is some way to get the photos that I'm seeing in the UI? These photos are public.

Real example:

UI from facebook: https://www.facebook.com/sonia.milan.9/photos You can see all his photos.

Using graph API: sonia.milan.9/albums Return:

{
  "data": [
  ]
}

Upvotes: 1

Guy
Guy

Reputation: 91

You can pass the "limit=0" to avoid paging altogether, and you get all the photos in one call.

Upvotes: 9

Umer Pasha
Umer Pasha

Reputation: 23

You use paging and offset to get next 5 or change the limit to whatever.

Upvotes: 0

Nishant
Nishant

Reputation: 55866

how do I get the entire album?

You need https://graph.facebook.com/[uid]/albums?access_token=[AUTH_TOKEN] to get JSON array of all the albums of a user.

You will get three important things from here id - album id, name - album name, and type - album type.

What permissions do I need?

The permission required is user_photos see here

What is the best way to get ALL profile pictures from a given user?

Profile Pictures are under "Profile Pictures" album. To get to profile album, you need to look into albums array (as mentioned previously), iterate through the JSON result-set, until you get an album with name = Profile Pictures and type = profile. Get id of this object. This is the profile pictures album.

Now you can access it similar to you access any other album. That is, https://graph.facebook.com/[ALBUM_ID]/photos?access_token=[AUTH_TOKEN] this will list all the profile pictures of the user ever uploaded.

Hope this helps.

refer: http://developers.facebook.com/docs/reference/api/

Upvotes: 54

Related Questions