Facebook graph API tells me I can get a profile picture of a user using
http://graph.facebook.com/517267866/picture?type=large
which works fine. However, whe
this is the only one that really works:
me?fields=picture.type(*YOURTYPE*)
where YOURTYPE can be one of the following: small, normal, album, large, square
The first URL gives a HTTP 302 (temporary redirect) to the second. So, to find the second URL programatically, you could issue a HTTP request for the first URL and get the Location
header of the response.
That said, don't rely on the second URL being pemanent. Reading a little in to the HTTP response code (of 302 as opposed to a permanent 301), it is possible Facebook changes those URLs on a regular basis to prevent people from—for example—using their servers to host images.
Edit: Notice that the CDN URL the OP posted is now a 404, so we know that we cannot rely on the URL being long-lived. Also, if you're linking to the Graph API from an <img>
on a SSL-secured page, there's a parameter you have to add make sure you use https://graph.facebook.com
.
Update: The API has added a parameter – redirect=false
– which causes JSON to be returned rather than a redirect. The retruned JSON includes the CDN URL:
{
"data": {
"url": "http://profile.ak.fbcdn.net/...",
"is_silhouette": false
}
}
Again, I wouldn't rely on this CDN URL being long-lived. The JSON response is sent with permissive CORS headers, so you're free to do this client-side with XHR requests.
function getFacebookImageFromURL($url)
{
$headers = get_headers($url, 1);
if (isset($headers['Location']))
{
return $headers['Location'];
}
}
$url = 'https://graph.facebook.com/zuck/picture?type=large';
$imageURL = getFacebookImageFromURL($url);
ImageView user_picture;
userpicture=(ImageView)findViewById(R.id.userpicture);
URL img_value = null;
img_value = new URL("http://graph.facebook.com/"+id+"/picture?type=large");
Bitmap mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream());
userpicture.setImageBitmap(mIcon1);
Where ID is one your profile ID.
I realize this is late, but there is another way to obtain the URL of the profile image.
To your original url, you can add the parameter redirect=false
to obtain the actual URL of the image you'd normally be redirected to.
So, the new request would look like http://graph.facebook.com/517267866/picture?type=large&redirect=false. This will return a JSON object containing the URL of the picture and a boolean is_silhouette (true if the picture is the default Facebook picture).
The picture will be of the size you specified, as well. You can test this additionally by adding dimensions: http://graph.facebook.com/517267866/picture?type=large&redirect=false&width=400&height=400
Now , Facebook need SSL
-> Important added S, https -> https://graph.facebook.com/userId/?fields=picture&type=large
Works In June / 2014