39

I want to display large photos in my Facebook app's feed view immediately. Is it possible to get the large photo src URL from a stream/feed using one API call? The photo id is returned in the stream/feed and one can of course then supply this photo id in an additional FQL or graph API call to retrieve all the information about that photo. However, is there a way using multi-query or batch calls to get a larger photo src url using one API roundtrip?

John Wright
  • 2,402
  • 4
  • 28
  • 32

6 Answers6

84

I haven't tried this with stream/feed photos, but the generally accepted way of doing this is:

http://graph.facebook.com/{ID of object}/picture

If you want the "large" version, you would do:

http://graph.facebook.com/{ID of object}/picture?type=large

I'm not 100% sure if this would work for an actual photo (instead of a user profile picture or page profile pic), but I have a hunch it will - the only caveat is that you obviously must have a logged in user that is authorized to view the photo (unless it's public).

streetlogics
  • 4,379
  • 30
  • 29
  • 7
    That actually works with a few twists. You need to use https, the type should be normal, not large, and you need an access token. Sweet, immediate access to a larger photo: For e.g. https://graph.facebook.com/993589032862/picture?type=normal&access_token=192822854100507|606f7dc18352cb2ea6f0c21c.0-710381977|ZoXpprWAwfM-13-Z2qmBy_L09qM – John Wright Sep 29 '11 at 17:21
  • 3
    @JohnWright: you do not need an access token for profile photo – Martin. Mar 12 '12 at 22:55
  • 4
    Supported types are small, normal, large or square, not just normal as John Wright claims. – Skela Aug 03 '12 at 06:55
  • 2
    Hmm, maybe it depends on what 993589032862 is? This works: https://graph.facebook.com/993589032862/picture?type=normal but this doesn't: https://graph.facebook.com/993589032862/picture?type=large . What is 993589032862, anyway? – Adam Monsen Sep 26 '12 at 19:37
  • Wouldn't this still require you to make another call for each photo to get the high resolution imagE? – Kasper Holdum Jul 28 '13 at 20:30
  • It is work for user profile image but I need posted (User's wall post) image in actual size. Because it is shows thumb size image. if any idea then please reply me. – Pratik Mar 07 '14 at 18:42
  • 1
    @Pratik - A quick search-a-roo brought me to this - http://stackoverflow.com/a/15069660/542550 `You can replace type=large with width=9999&height=9999 for the original size image: https://graph.facebook.com/someuser/picture?width=9999&height=9999` – streetlogics Mar 07 '14 at 19:48
  • @Pratik - Lucas down below said the same thing - http://stackoverflow.com/a/20194301/542550 – streetlogics Mar 07 '14 at 19:50
  • @streetlogics - it is working for users profile picture and I am talking about image which is in user's wall post. – Pratik Mar 10 '14 at 08:53
  • @Pratik - this might help - http://stackoverflow.com/questions/16419144/get-picture-object-from-facebook-post-with-graph-api – streetlogics Mar 10 '14 at 19:22
  • 1
    None of the above currently works with the /v2.0/ endpoints - /v2.0/{object_id}/picture?redirect=0&height=400&type=normal&width=400 gives you a 135x135 square photo – Dante Cullari May 13 '14 at 10:40
  • 1
    from the new documentation -> https://developers.facebook.com/docs/graph-api/reference/v2.0/user/picture – Dante Cullari May 13 '14 at 10:52
  • How to get feed posts it will not get – Vineesh TP Oct 20 '14 at 05:55
  • 2
    I just tried and `?type=large` is not supported, the largest is `?type=normal`. Also not requires an access token. I currently don't need `width` and `height` to get a "reasonable" (~720px) picture but who knows... – Hendy Irawan Aug 20 '15 at 23:51
31

If anybody is looking to this and type large is not enough, I found other solutions.

Type large is kind of small anyway (close to 200px). You can get larger image by adding i.e. ?width=1000 or ?height=1000. Facebook will return picture closest to given dimension and preserve aspect ratio. When passing both dimenstions like ?width=1000&height=1000, facebook will cut image to given dimensions (in this case square).

Lucas
  • 2,449
  • 1
  • 16
  • 16
2

Use Facebook UserId (Oject ID) to get the picture.

https://graph.facebook.com/173xxxx8635/picture?type=large&redirect=false

which returns JSON data with picture URL.

{
   "data": {
      "is_silhouette": false,
      "url": "https://fbcdn-profile-a.akamaihd.net/xxx/xyz/1cc066a2cae3f301d"
   }
}
Madan Sapkota
  • 21,350
  • 11
  • 100
  • 111
1

A good trick with the new api is to get the pic_cover field from the event table and to process it according to the size you want to use

user1445685
  • 405
  • 6
  • 16
1

I found when I was having this trouble that it turned out to be the picture I was downloading rather than the size I was setting it.

If for example I downloaded all my photos with a request of

[FBRequestConnection startWithGraphPath:@"/me/photos?fields=created_time,name,picture&type=tagged" parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection * connection, id result, NSError *error) {

    NSDictionary * userData = (NSDictionary *)result;
    NSMutableArray * array = [[NSMutableArray alloc] initWithArray:userData[@"data"]];

    for (NSDictionary * dict in eventsToAdd) {

        UIImage * image = dict[@"picture"] 
    }
}];

I am using the dictionary key search "picture" as I want the picture.

This though will get me a lower quality picture than if I searched for "source" in this search:

[FBRequestConnection startWithGraphPath:@"/me/photos?fields=created_time,name,source&type=tagged" parameters:nil HTTPMethod:@"GET" completionHandler:^(FBRequestConnection * connection, id result, NSError *error) {

    NSDictionary * userData = (NSDictionary *)result;
    NSMutableArray * array = [[NSMutableArray alloc] initWithArray:userData[@"data"]];

    for (NSDictionary * dict in eventsToAdd) {

        UIImage * image = dict[@"source"] 
    }
}];

If you go on the Facebook API explorer and search for photos and then click on the picture and source jpg links you can see the difference in size and quality.

Since changing this method I have managed to get rid of using the type parameters as it doesn't seem to make a different.

Note: I am using iPhone and not iPad or a larger screen so I don't know how this affects bigger screens.

simon_smiley
  • 5,613
  • 3
  • 39
  • 54
0

The answer by @streetlogics works fine but only on pictures that have {object_id}.

http://graph.facebook.com/{object_id}/picture

But I also wanted large pictures for the feed's shared links, which sometimes don't have {object_id}. I finally realized that the {picture} thumbnail URL contains the encoded URL for the original site's large image:

https://external.xx.fbcdn.net/safe_image.php?d=AQBe9UvGd0vPbAHP&w=130&h=130&url=http%3A%2F%2Fskift.com%2Fwp-content%2Fuploads%2F2015%2F12%2Fpollution.jpg&cfs=1

--> contains -->

http://skift.com/wp-content/uploads/2015/12/pollution.jpg

So I made a loop that checks for {object_id} and if not present then extracts the URL from {picture}:

if(isset($post['object_id'])) {
    echo "http://graph.facebook.com/".$post['object_id']."/picture";
    }
    elseif(isset($post['picture'])) {
        echo urldecode(preg_replace('/&cfs.*/', '', preg_replace('/.*url=/', '', $post['picture'])));
    } 
    else {
        echo "no_large_image";
}
williamtx
  • 81
  • 5