Facebook Graph API: Get post/status attached photo

2019-01-23 08:18发布

How can one get multiple attachments of a post/status in a group?

For example: A group status that some member wrote and added multiple photos to..

Currently I am using Graph api to get the group stream with group_id/feed and unable to see images attached to a single status - while accessing the feed from Facebook itself I can validate that there are few photos attached to the status.

Using FQL it is possible to get the attachments with the following query:

SELECT attachment FROM stream WHERE post_id = each_post_id

Considering I will have to send this request per post and that FQL will soon be gone I am searching for an alternative.

2条回答
虎瘦雄心在
2楼-- · 2019-01-23 08:44

I answered for the same question here : /v2.1/{post-id} does not deliver photos

It seems it's a Facebook bug. My colleague opened an issue. Here's the link: https://developers.facebook.com/bugs/762280800482269/
You also can find some info here:
https://developers.facebook.com/bugs/790976317600139/
Hope it will help you.

查看更多
再贱就再见
3楼-- · 2019-01-23 08:48

I was looking for a solution for this as well and actually just found it.

The Facebook Platform changelog says the following:

/v2.1/{post-id} will now return all photos attached to the post: In previous versions of the API only the first photo was returned with a post. This removes the need to use FQL to get all a post's photos.

With this knowledge I went to the Graph Api Explorer and found a post that had 2 attachments or more added to it.

After finding the post, and with that the post id, I tried the request Facebook told me to do:

/v2.1/{post_id}

This does NOT give you the desired result. The nice thing about the explorer is that you can search for fields you want to add to your request.

You want to add the attachments (plural) field. NOTE: It might be that the graph api explorer only shows the attachment (singular) field. This is NOT right.

So, to summarize:

  1. Get the post id of the post containing the images.
  2. Create a new request to the graph api that looks something like: /v2.1/{post_id}?fields=attachments

Then read the result to get your desired attachments.

I hope this helps you out as I have been struggling for a while as well.

KR

PS: This is tested with a user and not a group, but it should be basically the same.
PS2: This is just an explanation of how you get attachments of a single post. You can also add the attachments field to the /me/home egde to immediately get all attachments at every post like so:

me/home?fields=message,from,attachments

PS3: The permissions you need are

  1. user_status
  2. read_stream
  3. user_photos
  4. user_videos

Facebook is not very clear on this matter and it is very hard to figure things out like this. So I hope this will help everyone that is searching for this solution.

查看更多
登录 后发表回答