5

Is there a way to know if a user uploaded an image to the profile or it has the default user picture of Facebook via FQL or somthing else?

3 Answers 3

23

If a user doesn't have a photo then the is_silhouette field will be true when you request the user object with the "photo" field specified.

Example request:

https://graph.facebook.com/username?fields=picture

Response:

{
   "id": "100002095576350",
   "picture": {
      "data": {
         "url": "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",
         "is_silhouette": true
      }
   }
}

Quick, dirty PHP function:

function facebook_user_has_photo($username_or_id){

        $request = file_get_contents('https://graph.facebook.com/'.$username_or_id.'?fields=picture');

        if($request):

            $user = json_decode($request);

            if($user && !$user->picture->data->is_silhouette) return true;

        endif;

        return false;

}
0
8

You can use the Python script below (as not mentioned any programming language) to make it work.

urllib.urlopen('https://graph.facebook.com/<PROFILE_ID>/picture?access_token=%s' % access_token).geturl()

This will provide you a Facebook profile photo URL. If that URL contains <PROFILE_ID> then it uploads an image. Else the default Facebook image is uploaded.

For example, if uploaded image:

http://profile.ak.fbcdn.net/hprofile-ak-snc4/195361_<PROFILE_ID>_4179703_q.jpg

else:

For male:

http://b.static.ak.fbcdn.net/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif

For female:

https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/y9/r/IB7NOFmPw2a.gif

I hope this helps.

4
  • For PHP Developers, You can use: <?php print_r(get_headers("https://graph.facebook.com/<PROFILE_ID>/picture?access_token=" . $access_token)); ?> And find location into header :) Commented Apr 5, 2011 at 17:09
  • For male and female there are different pictures. So figure out how what locations for male/female. Also it's possible to check files by checksum. Commented Sep 2, 2011 at 0:40
  • What do you think, how often do then change location of those gif files? Commented Sep 17, 2011 at 5:06
  • i dont think... they need to change... if still then you need to keep checking these locations. Commented Sep 17, 2011 at 9:00
3

From my experiments with the Facebook API, it appears one has to actually get the picture in order to tell whether it's a static default one or not.

At the time of writing, it appears that all uploaded photos on Facebook are converted to JPEG, while the static default pictures are in the GIF format. (BTW, this is not consistent with some thumbnail sizes).

Looking for specific GIF file or a specific URL path is not reliable (note that there are CDN URLs involved, and that there are different static files for male and female). Assuming Facebook doesn't re-encode their entire profiles photos database, I suppose looking for a GIF is reliable enough.

Here's a sample PHP function to do this. I've tested it successfully with my 120 Facebook friends, and it seems to do the job.

public static function hasProfilePicture($fbuid) 
{
    /* Really stupid method to test if Facebook user has real profile picture
    * based on Facebook returning a GIF image when you request a large photo.  
    * Use with care - for every profile there's an outgoing request! */ 
    $r = get_headers("http://graph.facebook.com/$fbuid/picture?type=square"); 
    return !array_search("Content-Type: image/gif",$r);
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.