Getting full-size profile picture

后端 未结 7 1830
我寻月下人不归
我寻月下人不归 2020-11-30 19:40

Is there anyway to get the full-size profile picture using any facebook api?

http://graph.facebook.com/{ID}/picture?type=large is way to small.

Thanks :)

相关标签:
7条回答
  • 2020-11-30 20:19

    With Javascript you can get full size profile images like this

    pass your accessToken to the getface() function from your FB.init call

    function getface(accessToken){
      FB.api('/me/friends', function (response) {
        for (id in response.data) { 
            var homie=response.data[id].id         
            FB.api(homie+'/albums?access_token='+accessToken, function (aresponse) {
              for (album in aresponse.data) {
                if (aresponse.data[album].name == "Profile Pictures") {                      
                  FB.api(aresponse.data[album].id + "/photos", function(aresponse) {
                    console.log(aresponse.data[0].images[0].source); 
                  });                  
                }
              }   
            });
        }
      });
    }
    
    0 讨论(0)
  • 2020-11-30 20:22

    Set either the width or height to some arbitrarily large number:

    https://graph.facebook.com/username_or_id/picture?width=9999

    If the width and height are the same number, the photo is cropped to a square.

    0 讨论(0)
  • 2020-11-30 20:22

    For Angular:

    getUserPicture(userId) {   
    FB.api('/' + userId, {fields: 'picture.width(800).height(800)'}, function(response) {
      console.log('getUserPicture',response);
    });
    }
    
    0 讨论(0)
  • 2020-11-30 20:29

    As noted above, it appears that the cover photo of the profile album is a hi-res profile picture. I would check for the album type of "profile" rather than the name though, as the name may not be consistent across different languages, but the type should be.

    To reduce the number of requests / parsing, you can use this fql: "select cover_object_id from album where type='profile' and owner = user_id"

    And then you can construct the image url with: "https://graph.facebook.com/" + cover_object_id + "/picture&type=normal&access_token=" + access_token

    Looks like there is no "large" type for this image, but the "normal" one is still quite large.

    As noted above, this photo may be less accessible than the public profile picture. You need the user_photos or friend_photos permission to access it.

    0 讨论(0)
  • 2020-11-30 20:34

    Profile pictures are scaled down to 125x125 on the facebook sever when they're uploaded, so as far as I know you can't get pictures bigger than that. How big is the picture you're getting?

    0 讨论(0)
  • 2020-11-30 20:44

    found a way:

    $albums = $facebook->api('/' . $user_id . '/albums');
    foreach($albums['data'] as $album){
        if ($album['name'] == "Profile Pictures"){
            $photos = $facebook->api('/' . $album['id'] . '/photos');
            $profile_pic = $photos['data'][0]['source'];
            break;
        }
    }
    
    0 讨论(0)
提交回复
热议问题