13

I'm getting my page wall with the open graph. And when someone posted a photo, I get it on the JSON

{
     "id": "27888702146_10150369820322147",
     "from": {
        "name": "brocoli",
        "category": "Record label",
        "id": "27888702146"
     },
     "message": "Vincent Epplay / David Fenech / Jac Berrocal \u00e0 Beaubourg ce soir, 19h, gratos.",
     "picture": "http://photos-f.ak.fbcdn.net/hphotos-ak-snc7/305819_10150369820292147_27888702146_8255527_583491475_s.jpg",
     "link": "https://www.facebook.com/photo.php?fbid=10150369820292147&set=a.386279807146.165840.27888702146&type=1",
     "icon": "http://static.ak.fbcdn.net/rsrc.php/v1/yz/r/StEh3RhPvjk.gif",
     "type": "photo",
     "object_id": "10150369820292147",
     "created_time": "2011-10-16T08:22:21+0000",
     "updated_time": "2011-10-16T08:22:21+0000",
     "likes": {
        "data": [
           {
              "name": "brocoli",
              "category": "Record label",
              "id": "27888702146"
           },
           {
              "name": "Agathe Morier",
              "id": "601668526"
           }
        ],
        "count": 2
     },
     "comments": {
        "count": 0
     },
     "is_published": true
  }

The problem is that the picture link is a low resolution copy of the picture.

How can I get the URL of the full picture ?

Thanks!!

Best

Geoffroy

geoffroy
  • 575
  • 6
  • 18

5 Answers5

19

You can get different version of the photo by querying Graph API with its object_id (not photo post_id which is id in results you provided).

Once you'll request the photo by object id you'll get array of images with URLs and dimensions:

http://graph.facebook.com/10150369820292147?fields=images

If you're attempting to access posts on a Facebook Page (such as for a company) instead of typical user profile, you firstly need to fetch the feed like this:

https://graph.facebook.com/v15.0/YOUR_PAGE_ID_HERE/feed?fields=attachments&access_token=...

And then access data[0].attachments.data[0].subattachments.data[0].target.id to get the object ID (or "target ID" in this case) which you can then use to perform an additional query to obtain the higher resolution image. Increment the numbers to get additional posts and images inside each post.

danronmoon
  • 3,814
  • 5
  • 34
  • 56
Juicy Scripter
  • 25,778
  • 6
  • 72
  • 93
  • @Juicy Scripter What if i don't have an object_id in my feed. – saikiran Jul 14 '14 at 06:33
  • 2
    @Juicy Scripter, Thanks for the great answer but for the feed type "Video" it is failing with below response. {"error":{"message":"Unsupported get request. Please read the Graph API documentation at https:\/\/developers.facebook.com\/docs\/graph-api","type":"GraphMethodException","code":100}} – Engineer Jul 28 '14 at 00:29
  • 1
    @Juicy Scripter : not working ' Unsupported get request ' http://graph.facebook.com/397556853726341?fields=images – Vineesh TP Oct 15 '14 at 04:06
  • @VineeshTP working for me, perhaps you're not using the correct object_id field? – Kevin Mar 27 '15 at 02:00
5

All you need to do is :

http://graph.facebook.com/me?fields=picture.height(961) 
// replace 961 with your required height which u want
Rafique Mohammed
  • 3,666
  • 2
  • 38
  • 43
4

You can do this from the main posts list now using

/v2.3/105753476132681/posts?limit=5&fields=likes.summary(true),comments.summary(true), attachments

If attachments doesn't work, try full_picture - but that just gave the 100x100 image for me as well.

Attachments returns a data hash with a 640x480 version of the image at least (not sure what my orig. photo size was)

Kevin
  • 4,225
  • 2
  • 37
  • 40
  • This might work for a typical user feed, but not for a Facebook *Page*, which currently limits images to 720px. You instead need to use the [method mentioned above](https://stackoverflow.com/a/9821883/195835) by Juicy Scripter. – Simon East Jan 13 '23 at 15:16
2

Use this Code. Its Work for me and get Clear Image

String PICTURE_URL;

String getPicture = hashMap.get("picture");
        if (getPicture.contains("_t.")) {
            PICTURE_URL = getPicture.replaceAll("_t.", "_n.");
        } else if (getPicture.contains("_a.")) {
            PICTURE_URL = getPicture.replaceAll("_a.", "_n.");
        } else if (getPicture.contains("_s.")) {
            PICTURE_URL = getPicture.replaceAll("_s.", "_n.");
        } else if (getPicture.contains("_q.")) {              
            PICTURE_URL = getPicture.replaceAll("_q.", "_n.");
        }
        url=new URL(PICTURE_URL);
        Bitmap bitmap=BitmapFactory.decodeStream(url.openConnection().getInputStream());
        ((ImageView)view.findViewById(R.id.imageView_FullImage)).setImageBitmap(bitmap);
Manoj Kumar
  • 177
  • 1
  • 11
2

Though requesting a photo by its object_id will return an array of images with different dimensions, in some cases this approach would require an additional call to the Facebook API.

A simpler approach is to add full_picture to your list of parameters, which will extract the highest resolution image associated with the post.

/v2.2/6275848869/posts?fields=full_picture

For example, if you want to extract all the posts from a Facebook page in the past X days, with the object_id approach you'd need to call the API 3 times:

  1. To get the page info.
  2. To extract the list of posts and obtain the object_id for each post.
  3. For each object_id, to retrieve the list of higher resolution images.
Nicole
  • 29
  • 1
  • Unfortunately this has two problems: it doesn't fetch the highest resolution when used on Facebook posts assigned to a "Page", and it only fetches a single image. Some posts can have multiple images attached. – Simon East Jan 13 '23 at 14:58