post tweets from terminal
- post tweets from terminal like this
python3 twt.py "this tweet have been posted from my terminal"
-
Get API keys from developer.twitter.com.
- Make a project/app, enable OAuth 1.0a
- Set to "Read and Write" perms (IMPORTANT)
- Copy your API Key and API Secret (also called
consumer_key
andconsumer_secret
)
-
Create a file named
secrets.json
in the same directory as the script.
{
"consumer_key": "your_api_key",
"consumer_secret": "your_api_secret"
}
-
Paste this in your config file and replace
your_api_key
andyour_api_secret
with the actual keys you obtained from Twitter. -
Run the script for the first time, passing the tweet text as an argument:
python3 twt.py "{text}"
- The script will output a URL like this, open it and authorize the app.
Please go here and authorize: https://api.twitter.com/oauth/authorize...
- Twitter will give you a PIN code. Copy it and paste the PIN code into the script when it asks:
Paste the PIN here:
- The script will complete the OAuth process and you will be able to post tweets using the script normally.
- Python 3.x installed
requests_oauthlib
library installed
For more information about Twitter API OAuth, see: