Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a Facebook user has uploaded a profile picture or its default?

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?

like image 450
amirash Avatar asked Apr 05 '11 16:04

amirash


1 Answers

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;

}
like image 83
Adam Avatar answered Oct 04 '22 22:10

Adam