3

My goal is to pull latests posts from given page. This works just fine using API endpoint {page_id}/posts. Some of the posts are of type="photo" and have fields picture and full_picture. Trouble is, those image urls are small, more like thumbnails than images.

I noticed that lately there is another field object_id that comes with any post of type photo. Making request to {object_id}/picture?redirect=false returns a url to an image.

I would like to get the url from {object_id}/picture when pulling posts from {page_id}/posts, but i can't find a way of doing it. I tried to nest the request {page_id}/posts?fields=object_id.fields(picture), and all i got is Subfields are not supported by object_id.

How can i get the url to an image posted by the page?

Edit

Just to clarify my question:

I want to pull all latest posts for given page. And for posts with type="photo" i want to pull image url in addition to other fields, like message. Preferably, without additional request to Graph API.

My usual request looks like this:

{page_id}/posts?fields=id,object_id,message,description,full_picture,source

This brings all kinds of posts for the page_id. full_picture is a url to thumbnail-sized image. I would like to get a url to same image with bigger size, if it's possible.

Neara
  • 3,693
  • 7
  • 29
  • 40
  • Well, your question give the answer to my question... This might solve your question: http://stackoverflow.com/questions/17438847/using-facebook-graph-api-how-to-get-news-feed-with-large-picture-size-if-the-fee – Jennie Ji Aug 20 '15 at 08:53

3 Answers3

2

Query for attachments field. Like this:

{page_id}/posts?fields=attachments,id,object_id,message,description,full_picture,source

This will give you full-sized images.

Notice that this may not work for status update posts.

ecdeveloper
  • 2,777
  • 1
  • 22
  • 16
0

You can do this in FQL:

select pid, object_id, src_big from photo where pid in (select attachment.media.photo.pid from stream where source_id={PAGE_ID} and type=247)

where {PAGE_ID} is the numeric id of your Page.

Tobi
  • 31,405
  • 8
  • 58
  • 90
  • can this be adapted to pulling all types of posts from the page? and for posts with `type="photo"` pull `src_big` as well? – Neara Jun 05 '14 at 09:17
  • This FQL pulls exactly what you asked for: For all `photo` posts of a Page the large photo respresentation `src_big`. See https://developers.facebook.com/docs/reference/fql/stream/ – Tobi Jun 05 '14 at 09:22
  • what i'm asking is to pull all latest posts for given page. Those posts can be of different types. One of the types i see is photo, and those posts have url to thumbnail of the photo. I'm trying to find a way to get photo url, while extracting latest posts of all kinds. I will edit my question to clarify this. – Neara Jun 05 '14 at 09:27
  • Just "a" thumbnail is already contained in the original post. I really urge you to detail as far as possible WHAT you want to do. It somehow sucks when one answers a question, and the OP then makes up his mind and changes the scope. You question was: `How can i get the url to an image posted by the page?` – Tobi Jun 05 '14 at 09:30
  • you are absolutely right. I'm sorry, i just edited my question. Thank you for pointing it out! – Neara Jun 05 '14 at 09:35
0

Use the picture field to get the thumbnail URL. That's the most you'll be able to get from a single API call. But you can modify that URL to bring in the full resolution picture. Check out this answer.

https://stackoverflow.com/a/22897707/1754999

If you use Picasso, you can check for a redirect error in loading (in case that method doesn't work) and set up another API call to the object_id of the post. The source field in that API call will be the full resolution image, but only use that if the above method doesn't work.

EDIT: You basically replace _s with _n or _o in the URL.

Community
  • 1
  • 1
Wenger
  • 989
  • 2
  • 12
  • 35
  • yeah, i used to change `_s` with `_n`, it worked for sometime, but lately i got images where this method didn't work. changing to `_n` only brought a 1px by 1px image, but when i got the url via `object_id` i got large image. didn't know about `_o` thing, will try that, ty ;) – Neara Jun 08 '14 at 07:55
  • Awesome! ty for directing me to the other question, i didn't find it before, and it helped me solve my issue. It looks like this solution works for graph api v1.0 only, correct me if i'm wrong. Next year we will have to find another solution then. – Neara Jun 08 '14 at 08:15
  • I've been using it with 2.0. Also using `_n`. – Wenger Jun 08 '14 at 12:33
  • i was referring to `'https://graph.facebook.com/' + object_id + '/picture'` part. it's a call to api v1.0. For the moment i changed all images to go though `object_id` and it works beautifully. Still have to use `_n` for videos tho. – Neara Jun 08 '14 at 12:49