Warm tip: This article is reproduced from serverfault.com, please click

Facebook graph api page post with multiple photos

发布于 2020-12-01 10:58:10

I am trying to publish a page post with multiple photos via the Facebook's graph api.

Currently from the docs and another question here it's stated that the photos should be uploaded separately and then publish the post with attached_media parameter.

The photos are uploaded fine without any problem and I get their IDs. The issue is that the request for publishing the post gives:

{
  "error": {
  "message": "An unknown error has occurred.",
  "type": "OAuthException",
  "code": 1,
  "fbtrace_id": "SOME TRACE ID"
}

If I remove the attached_media parameter from the request the post is published fine.. Any Idea what can be the issue?

Specially for CBroe here are the reqiests: For the photo upload:

endpoint: /{page-id}/photos

payload:

{
  "url": "some-image-url",
  "caption": "Some image caption",
  "published": false
}

endpoint: /{page-id}/feed

payload:

{
  "message": "Some post message",
  "published": false,
  "attached_media": [
    {"media_fbid": "PHOTO_ID_RETURNED_FROM_THE_ABOVE_REQUEST"}
  ]
}

The payload is send as json to the endpoint. This request works only if I remove the attached_media parameter.

Questioner
Alexander Dimitrov
Viewed
0
Alexander Dimitrov 2020-12-03 19:41:18

TL;DR

Add publish_to_groups permission to the access token and the request for the post should be with parameter published: true. It appears to have a bug in the graph api or lack of information in the official docs.

Details:

Currently in order to publish a page post with multiple photos you will need to:

  • upload individually the photos and obtain their IDs
  • use PAGE access token which contains publish_to_groups permission
  • attach all photo IDs with attached_media[0..N]: {"media_fbid": "PHOTO_ID"}
  • currently the request for publishing the post fails if it's with parameter published: false, so it needs to be published: true

All of this does not make really sense to me, so I opened a bug report in the developers platform of Facebook. It does not looks right during development of the App to publish live posts to the page...

I'll edit the answer once I have a feedback.