0

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.

Alexander Dimitrov
  • 944
  • 1
  • 6
  • 17
  • _“Any Idea what can be the issue?”_ - since you neglected to show us what you are actually doing: No. – CBroe Dec 01 '20 at 11:24
  • Are you serious? I described exactly what the issue is.. what do you need to know more? I will edit the question. – Alexander Dimitrov Dec 01 '20 at 11:27
  • Of course I am serious, we don’t know what _exact_ request you attempted, so based on what information you have provided so far, everything else would be guesswork. Please go read [ask], if you have not done that yet. Rule of thumb is - show _code_ of what you are doing, instead of giving just a verbal paraphrased explanation, that could potentially still mean a lot of different things, when it comes to the details. – CBroe Dec 01 '20 at 11:29
  • I edited the question, but I don't really agree with you here.. This question is not about the coding, it's about the principles. Posting a code in particular language will just be confusing. – Alexander Dimitrov Dec 01 '20 at 11:39
  • So what exact documentation are you referring to here? The only context I can find `attached_media` mentioned in, is when _updating_ an existing post. – CBroe Dec 01 '20 at 11:46
  • edited with the links.. – Alexander Dimitrov Dec 01 '20 at 11:53
  • The examples there use cURL’s `-d` option, which means the request will be `application/x-www-form-urlencoded`, not JSON. Only the value of the parameter is JSON in what they show there, but notably the parameter names are `attached_media[0]`, etc. I’d first of all try and send that format, and see if that changes anything. – CBroe Dec 01 '20 at 12:01
  • I tried with the cURL request in the terminal, using the PHP SDK and with another PHP HTTP Client. All results are the same. Also I tried what you proposed, to use parameter names as `attached_media[0...N]` and json encoded value, but nothing works.. – Alexander Dimitrov Dec 01 '20 at 12:05
  • And the IDs you are using a actual photo IDs for sure, and not perhaps IDs of corresponding page posts that might have been created along with the photo upload? – CBroe Dec 01 '20 at 12:11
  • The IDs are whatever ID `/{page-id}/photos` request returns. The format is just a digit, in comparison the page ID is composed by two digits combined with `_` /underscore/. – Alexander Dimitrov Dec 01 '20 at 12:16
  • So are these just any arbitrary photos you fished out of the page’s existing albums now, or where they specifically uploaded using your app? (Not sure whether that is relevant, trying to narrow down the issue here.) – CBroe Dec 01 '20 at 12:18
  • The photos are specifically uploaded to compose a page post, so no existing photos are used from the albums. – Alexander Dimitrov Dec 01 '20 at 12:19

1 Answers1

5

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.

Alexander Dimitrov
  • 944
  • 1
  • 6
  • 17
  • Hi @alexander-dimitrov have you got any news from facebook about your bug report ? – bohr May 16 '21 at 03:03
  • After trying it myself, I can confirm that it needs to be published:true for it to work. But as I suspected, the permission "publish_to_groups" has nothing to do with this as we publish only to a page (it does not even appear to the access settings shown to the user). I will also add that neither published:false + unpublished_content_type:DRAFT or published:false + unpublished_content_type:SCHEDULED works. Im going to open a bug too, that's not acceptable to be forced to directly publish and it's unusable for testing purposes. – bohr May 16 '21 at 04:53
  • I have exactly the same issue and I agree: it's not acceptable to be forced to directly publish. Do you already have more feedback from Facebook? – Frank P Jun 04 '21 at 20:36
  • @Frank P https://developers.facebook.com/support/bugs/810817199551294/ – bohr Jun 09 '21 at 23:01
  • 3
    Okay I have some news, it now works !! They have updated their doc, you must add "temporary=true" as a parameter when you upload the images and then both DRAFT and SCHEDULED work : https://developers.facebook.com/docs/graph-api/reference/page/photos/#single – bohr Jun 10 '21 at 21:56