There are three main components to automate the Twitter post-blast, which are the Python script, media library, and schedule module. In this Python Tutorial, I would walk you through how to code the Twitter post automation script that connects with the Google Sheets and add schedule modules.
Table of Contents: Twitter Post Automation Using Easy2Digital API and Python
- Twitter App Creation and Authentication
- Post Content Prepared Upfront Saved on Google Sheet
- Update_status & update_status_with_media
- Schedule module
- Full Python Script of Twitter Post Automation
- FAQ
Python modules: Easy2Digital API, gspread, schedule, Tweet API access token
Twitter App Authentication
Compared to my previous article regarding Twitter bot scraping influencers and grabbing sentiment data, Twitter posts need one more step to authenticate your app. This is the user authentication setting. For more details regarding Twitter developer accounts, please refer to this article.
There are three key steps we need to update in the authentication process. First thing first, we select the app permission in a read and write mode, instead of only read mode. This is essentially different from the Twitter bot.
Then, we need to input the redirect URL and website URl. You can refer to my inputs or set up a localhost URI based on the needs.
- Callback URI / Redirec. t URL: https://twitter.com/easy2digitals
- Website URL: https://www.easy2digital.com
Manage to-be-posted content upfront on Google Sheet
In one Google sheet tab, we are able to prepare all elements a Tweet needs, such as post body, photos, landing URLs. And if you have other channels blasting the same piece of post, you also can centralize to manage there
For more details regarding how to install and import gspread, please check out previous Python Tutorials. Basically, we need to import gspread, create a Google credential account in the Google APIs Console, and get access to the Google Sheet you manage content.
In terms of the scope of Google API, the automation needs google drive, and google sheet read and write.
Update_status & update_status_with_media
In the Tweepy post update, there are two methods we can use. One is the update_status
which is posting a tweet where it includes text, and links. The other is, which is attaching a photo separately instead of using the detected images from the URL link. Below is a screencap from my Twitter posts. I personally prefer to use update_status, because users can click through the photo to the website.
Schedule Module
Python schedule module helps developers to automate executing the tasks as long as the device is in running status, like a laptop. So if you are a social marketer one day, you can use this module to help you blast the content automatically. The only cons of this approach are your device must be open.
# After eve. ry 10mins easy2digital() is called.
schedule.every(10).minutes.do(easy2digital)
# After every hour easy2digital() is called.
schedule.every().hour.do(geeks)
# Every day at 12am or 00:00 time easy2digital() is called.
schedule.every().day.at("00:00").do(easy2digital)
# After every 5 to 10mins in between run easy2digital()
schedule.every(5).to(10).minutes.do(easy2digital)
# Every monday easy2digital() is called
schedule.every().monday.do(easy2digital)
# Every tuesday at 18:00 easy2digital() is called
schedule.every().tuesday.at("18:00").do(easy2digital)
# Loop so that the scheduling task
# keeps on running all the time.
while True:
# Checks whether a scheduled task
# is pending to run or not
schedule.run_pending()
time.sleep(1)
Full Python Script of Twitter Post Automation
If you are interested in the full Python script of Chapter 49 – Twitter Post Automation Using Twitter and Easy2Digital API, please subscribe to our newsletter by adding the message “Chapter 49”. We would send you the script immediately to your mailbox.
I hope you enjoy reading Chapter 49 – Twitte. r Post Automation Using Twitter and Easy2Digital API. If you did, please support us by doing one of the things listed below, because it always helps out our channel.
- Support and donate to our channel through PayPal (paypal.me/Easy2digital)
- Subscribe to my channel and turn on the notification bell Easy2Digital Youtube channel.
- Follow and like my page Easy2Digital Facebook page
- Share the article on your social network with the hashtag #easy2digital
- Buy products with Easy2Digital 10% OFF Discount code (Easy2DigitalNewBuyers2021)
- You sign up for our weekly newsletter to receive Easy2Digital latest articles, videos, and discount codes
- Subscribe to our monthly membership through Patreon to enjoy exclusive benefits (www.patreon.com/louisludigital)