10

I'm using facebook graph api, and I issue this command

/V2.0/me/home

it returns something like :

  "id": "xxxxxxxxxxxxxxxxxxxxxx", 
  "from": {
    "id": "xxxxxxxxxxxxxxxxx", 
    "name": "Roger"
  }, 
  "story": "Roger shared a link.", 
  "picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQB2VeutsxS6ht3i&w=154&h=154&url=https%3A%2F%2Fwww.facebook.com%2Fads%2Fimage%2F%3Fd%3DAQIuWnred6mG7Ti280buWL8uhE00-W2H0Eom1PzNa3Av0x3y7JieMPqLmxAFYsCRKh0Zr8u_PyWO1lFbTknlj_DaksBoFiaD8d2yIWLOGNYKie1w9Kff6vyyElxnfrlHH7uSRhwycKNakg7szgWtBBwC", 
  "link": "http://xxxxxx.com", 

the issue is with the "picture" tag above, where the url to the picture is given after.

If you paste that url into your browser you get a small thumbnail size image, but on the real facebook page, its shows a much larger high resolution version of the same image.

This is the same for all the picture urls it sends back. Some url ends with _s.jpg, and I can change that to _n.jpg to make it a larger image, but that doesnt work for urls that doesnt have _s.jpg at the end, like the url above.

Anybody knows the facebook-graph-api command to use, so that facebook will send the url that points to the larger high resolution image instead of sending back urls that point to all thumbnails? Or how to change the url so that it points to the large high res image?

Thanks

N S
  • 303
  • 4
  • 17

5 Answers5

10

Using the user's id in place of <id>, you can get a larger resolution image at:

http://graph.facebook.com/<id>/picture?type=large

Chase Finch
  • 5,161
  • 1
  • 21
  • 20
NodeDad
  • 1,519
  • 2
  • 19
  • 48
  • This method works great but the types have changed. Supported types are `thumbnail`, `normal` and `album`. – David Blurton Feb 17 '15 at 14:16
  • do you still need to send your tokens when requesting the image from facebook? – Alex Pelletier Jul 31 '15 at 07:28
  • Types are now: small, normal, album, large, square. But even large is only 203x200 pixels. And I think this graph endpoint only gets your profile pic, not images from your feed. – Simon East Jan 13 '23 at 16:19
4

After you get the "id" of a post in your news feed use (in JavaScript)

pic_url = 'http://graph.facebook.com/'+ post_id +'?fields=full_picture&access_token="+ response.authResponse.accessToken;

in your request.

Example response:

{
   "full_picture": "https://fbexternal-a.akamaihd.net/safe_image.php?d=AQBbJqpkt2Jhf0VF&url=http\u00253A\u00252F\u00252Fwww.mixofpix.eu\u00252Fwp-content\u00252Fuploads\u00252F2014\u00252F08\u00252Flampa-oblak.jpg",
   "id": "1407721719477425_1467737580142505",
   "created_time": "2014-08-07T20:00:51+0000"
}
3

Get the ObjectId from field "object_id" for a specific post from your news feed

Use this object_id value to make a separate Graph API call as follows -

https://graph.facebook.com/10152199489086727?fields=images&access_token=

This will return the list of images of varying sizes for this post.

Example output:

{
    "images": [
    {
        "height": 462, 
        "source": "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpf1/t1.0-9/10302057_10152199489086727_707407897349696496_n.jpg", 
        "width": 616
    }, 
    {
        "height": 320, 
        "source": "https://fbcdn-sphotos-h-a.akamaihd.net/hphotos-ak-xpf1/t1.0-9/p320x320/10302057_10152199489086727_707407897349696496_n.jpg", 
        "width": 426
    },.... ..
    ], 
    "created_time": "2014-07-23T18:15:16+0000", 
    "id": "10152199489086727"
}
Satyajit Paul
  • 335
  • 2
  • 8
  • Iam getting Error : ' Unsupported get request. Please read the Graph API documentation at developers.facebook.com/docs/graph-api – Vineesh TP Oct 20 '14 at 05:33
  • this object_id doesn't exist for 'link' type of posts? – Joe Huang Dec 17 '14 at 01:12
  • 1
    Each type seems to need a different method I asked a question about it in order to create a cooperative list of these methods but I got 2 down votes in 10 minutes, it's a shame :S http://stackoverflow.com/questions/29233382/getting-large-images-from-facebook-with-graph-api-v2-2-by-typefeed-post-photo-l – nach Mar 24 '15 at 13:34
2

Try specifying the attachments field in your request.

/v2.0/me/home?fields=attachments

This will give you an 'attachments' field, with some media inside. You'll find there high res images.

ecdeveloper
  • 2,777
  • 1
  • 22
  • 16
  • The URL is now `/v15.0/me/feed` and unfortunately this won't quite give you the full resolution in some cases. [See this thread](https://stackoverflow.com/a/45815563/195835) for more on how to do that. – Simon East Jan 13 '23 at 16:20
0

You can get the original image URL by grabbing the value of the url query string variable in the 'picture' property of the post and decode it:

var origImgSrc = decodeURIComponent(picture.match(/(url=)([^&]+)/)[2]);

The other (more thorough/heavier) alternative would be to send a batch request to the Facebook Graph API, with the first request getting the feed from me/home/ and then the second using ?ids= to look up any returned object_id properties (for photos/videos on Facebook).

You would do this by sending a POST request to https://graph.facebook.com with the following in the request body:

access_token=VALID_ACCESS_TOKEN&batch=[{%20%22method%22:%22GET%22,%22name%22:%22me_home%22,%20%22relative_url%22:%22me/home?fields=object_id,full_picture%22,%20%22omit_response_on_success%22:false},%20{%20%22method%22:%22GET%22,%20%22depends_on%22:%22me_home%22,%20%22relative_url%22:%22?ids={result=me_home:$.posts.data.*.object_id}%22}]

Then you can do some fancy JS parsing to get either the full_picture property or one of the source properties from the images array for the object.

Iain Simmons
  • 340
  • 1
  • 2
  • 10