Search code examples
facebookfacebook-messengerfacebook-messenger-bot

Allow my app post on my facebook page


I have a chatbot in facebook that receives images from users and make some adjustments.

Then, I want the chatbot to post the images on the facebook page automatically. Is there a way to achieve that?


Solution

  • Yes there is always a way. Here's how I would do this.

    First read this on how to use the page section of the graph-api.

    You need to give your app these permissions https://developers.facebook.com/docs/facebook-login/permissions#reference-manage_pages. The manage_pages and publish_pages allow your app to post on the page.

    STEP 1. Your bot sends the image to the server for processing.

    STEP 2. Add the graph-api sdk to your project.(You might have this already)

    STEP 3. Get the ID of the page you want to post to

    STEP 4. Since you will be uploading images, you need to check this posting photos to facebook page via graph-api to post your images. It's basically sending a POST request to https://graph.facebook.com/ /v2.8/{page-id}/photos with the image as a param called source.

    1: Attach the photo as multipart/form-data. The name of the object doesn't matter, but historically people have used source as the parameter name for the photo. How this works depends on the SDK you happen to be using to do the post.

    2: Use a photo that is already on the internet by publishing using the url parameter:

    Now if everything is setup properly, you should be able to post from your server to the page with the ability to add captions etc.