Facebook API: Get all profile pictures

后端 未结 6 1389
野的像风
野的像风 2020-12-23 21:26

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.fa

相关标签:
6条回答
  • 2020-12-23 22:05

    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/

    0 讨论(0)
  • 2020-12-23 22:07

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

    0 讨论(0)
  • 2020-12-23 22:17

    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": [
      ]
    }
    
    0 讨论(0)
  • 2020-12-23 22:19

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

    0 讨论(0)
  • 2020-12-23 22:20

    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)); 
    
    0 讨论(0)
  • 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

    0 讨论(0)
提交回复
热议问题