I am trying to make a post to a Facebook page using the Graph API that includes an image. I have successfully done it with a two step process:
- Post to ‘https://graph.facebook.com/PAGE_ID/photos?url=IMAGE_URL&access_token=ACCESS_TOKEN‘
- Taking the image id from the return data from the post and making another post to ‘https://graph.facebook.com/PAGE_ID/feed?published=true&message=MESSAGE_TEXT&object_attachment=IMAGE_ID&fields=permalink_url&access_token=ACCESS_TOKEN‘
However, when I do that, FB posts the image to the page first and then posts the message with the image in it. Not ideal; I only want a single post with message and image.
I then tried keeping the image unpublished (adding &published=false to my image post). That worked to keep the image from posting on the page and I got an OK message with the image id back from FB. However, I received an error code (1 – “An unknown error occurred”) from the FB API when I went to post the message with image.
I also tried to keep the image unpublished and flag that as temporary (adding &published=false&temporary=true to my image post) with the same result.
Anyone know how to post a message with image to a page without first posting the image to the FB page?
2
Answers
You can add a
caption
to your image post.Or add the image as form data while creating the post.
Which Framework do you use?
The
no_story
parameter can be used to suppress the automatic creation of a feed story for the photo upload.https://developers.facebook.com/docs/graph-api/reference/photo#Creating: