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?
问题:
回答1:
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.
回答2:
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;
}
回答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);
}