You can render the current profile picture for any object that has a picture associated with it. All you have to do is add the suffix /picture to the object URL. For example, this will render a public profile picture:
<img src="https://graph.facebook.com/mike.shaver/picture">
The picture returned is very likely to be a redirect to a raw CDN URL. You should be prepared to handle HTTP redirects. Access to pictures is subject to rate limits. Please see the note about rate limits below.
If you need a picture to be returned over a secure connection, you can set the return_ssl_resources argument to 1: http://graph.facebook.com/shaverm/picture?return_ssl_resources=1. This is required because SSL and non-SSL resources might redirect to different locations.
You can add a redirect=false to the HTTP request to get the location instead of the actual data. This call:
<img src="https://graph.facebook.com/shaverm/picture?redirect=false">
will return JSON-encoded data describing the location of the picture. url is the location of the image and the is_silhouette boolean indicates whether or not the object has set a picture.
{
"data": {
"url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-ash4/372183_100002526091955_998385602_q.jpg",
"is_silhouette": false
}
}
You can also add the generic Graph API argument callback=your_callback_name to the call and it will return the same JSON data, but wrapped in a named JSON object with your name. (You can use the callback argument with just about any Graph API call. It makes it easier to build JS-enabled applications because the callback name can be passed into the original call and can be routed by name instead of by callback.)
For example, this call:
<img src="https://graph.facebook.com/shaverm/picture?callback=foo">
Will return this:
foo({
"data": {
"url":"http://profile.ak.fbcdn.net/hprofile-ak-ash4372183_100002526091955_998385602_q.jpg",
"is_silhouette":false
}
});
Like many APIs at Facebook, access to pictures are rate limited to prevent abuse. It's a very common problem for applications to run into rate limits with pictures when an application becomes even slightly popular. The best way to avoid rate limiting problems is to pass an access_token=token parameter along with the request.
To learn more about access tokens, login and authentication please see that section of the Graph API Getting Started Guide.
Some objects, especially groups, apps and pages, may have geographic or age restrictions that limit access to that object's picture. For these objects, you will need to make an authenticated request to get the picture that allows you to see the data from an account that can see the data.
For example, for a page that's labeled 18+ you will need to have an access token from an account that is more than 18 years old.
Here are some example objects that you can add the picture argument to:
| Object | Image | Example |
|---|---|---|
| People |
|
http://graph.facebook.com/shaverm/picture |
| Events |
|
http://graph.facebook.com/331218348435/picture |
| Groups |
|
http://graph.facebook.com/203905803086416/picture |
| Pages |
|
http://graph.facebook.com/DoloresPark/picture |
| Applications |
|
http://graph.facebook.com/2318966938/picture |
| Photo Albums |
|
http://graph.facebook.com/376995711728/picture |
There are two ways you can specify sizes. You can either use the type argument to get pre-specified sizes:
|
50px Wide 50px High |
|
http://graph.facebook.com/shaverm/picture?type=square |
|
50px Wide Variable Height |
|
http://graph.facebook.com/shaverm/picture?type=small |
|
100px Width Variable Height |
|
http://graph.facebook.com/shaverm/picture?type=normal |
|
200px Wide Variable Height |
|
http://graph.facebook.com/shaverm/picture?type=large |
Or you can use the width and height argument. The image returned will:
width and height have the same value.Examples:
|
40px Wide 60px High |
|
http://graph.facebook.com/shaverm/picture?width=40&height=60 |
|
60px Wide 150px High |
|
http://graph.facebook.com/shaverm/picture?width=60&height=150 |
|
200px Wide 200px High |
|
http://graph.facebook.com/shaverm/picture?width=200&height=200 |