Simply fetch the data through this URL:
http://graph.facebook.com/userid_here/picture
Replace userid_here
with id of the user you want to get the photo of. You can also use HTTPS as well.
You can use the PHP's file_get_contents
function to read that URL and process the retrieved data.
Resource:
http://developers.facebook.com/docs/api
Note: In php.ini
, you need to make sure that the OpenSSL extension is enabled to use thefile_get_contents
function of PHP to read that URL.
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.
Best Answer
Facebook got rid of the username because the username is one way of sending emails via Facebook.
For example, given the url
http://www.facebook.com/sebastian.trug
the corresponding Facebook email would be
sebastian.trug@facebook.com
which, if emailed, would be received to
messages
directly (if themessage
setting is set topublic
), otherwise to theother
inbox.