Automating Facebook page posts using python script

Automating your Facebook page post is extremely easy. All you need is Graph API token and Python code.


Getting Page Access Token:

Create a facebook app on developer.facebook.com


facebook developer app


Change the app status to live to make it public. 

Go to tools -> Graph Api explorer.


graph api explorer


Select your application.

Select page access token and then select the page name on which you want to post message using python code.

Select the 'i' icon at the start of access token.


page access token facebook



Click on 'Open in Access Token Tool'.

On the next page, click on on 'Extend Access Token'.



page access token facebook extended


Copy this access token and keep in config file. Remember not to commit this token into git.


Python Code:

It is recommended that you create a virtual environment using python3.

Activate the virtual environment and install the facebook-sdk==2.0.0 package.

source path-to-venv/bin/activate
pip install facebook-sdk==2.0.0


Use below code to post on your page on behalf of your facebook app your created above.


import facebook

page_access_token = "YOUR TOKEN GOES HERE"
graph = facebook.GraphAPI(page_access_token)
facebook_page_id = "67509909999999"
graph.put_object(facebook_page_id, "feed", message='test message')

After executing above script, verify on your page if post has been published or not.


automated post fb page


You can schedule a cron to post the status on facebook page regularly. 

Remember to renew the page access token before it expires.

Feel free to comment in case of any issue.


Host your Django App for Free.





Related Articles:
Python Script 16: Generating word cloud image of a text using python
word cloud python, generating a word cloud of a text using python code, python code to generate a word cloud image of a text. Using word frequencies to generate a word cloud image using a python script...
Python Script 13: Generating ascii code from Image
Generating ascii art from image, converting colored image to ascii code, python script to convert image to ascii code, python code to generate the ascii image from jpg image....
Python Script 17: Setting bing image of the day as desktop wallpaper
Python Script to Set bing image of the day as desktop wallpaper, Automating the desktop wallpaper change to bing image of day using python code, changing desktop wallpaper using python, downloading an image using python code, updating the desktop wallpaper daily using python...
Python Script 1: Convert ebooks from epub to mobi format
Python script to convert the ebooks from one format to another in bulk, Automated book conversion to kindle format, Free kindle ebook format conversion, automating the book format conversion, python code to book format convert,...

0 thoughts on 'Automating Facebook Page Posts Using Python Script'
Leave a comment:


*All Fields are mandatory. **Email Id will not be published publicly.


SUBSCRIBE
Please subscribe to get the latest articles in your mailbox.


Recent Posts:






© 2017-2019 Python Circle   Contact Us   Advertise with Us