Send tweets (with optional images) and authenticates through the Twitter v2 API (OAuth 2.0) using Python.
Send a test tweet with the following steps:
- generate and set the following environment variables:
- TWITTER_CONSUMER_API_KEY
- TWITTER_CONSUMER_API_KEY_SECRET
- TWITTER_ACCESS_TOKEN
- TWITTER_ACCESS_TOKEN_SECRET
- TWITTER_CLIENT_ID
- TWITTER_CLIENT_SECRET
- TWITTER_CALLBACK_URI <- (ie.
http://localhost/callback
to match the route inserver.py
)
- authorize the application (1 time only) to generate the seed
token.json
with the following:- run the token generation server by executing
Authenticate/authenticate.sh
(Docker) orpython3 -m Authenticate.src.server
(Python3) - navigate with a browser to http://localhost/auth
- run the token generation server by executing
- send a test tweet by executing
example/test.sh
(Docker) orpython3 -m example.test
(Python3)
- either:
- Docker engine or
- Python3 with
flask requests requests-oauthlib
- Twitter project with:
- v1.1 API read & write access (for attaching images to tweets)
- v2 API access
- write separate PyPI instructions
- document interfaces
- give a more verbose explanation of the steps
- add geolocation to tweets:
- try posting with the v1 API instead of v2:
- wait for an answer to https://stackoverflow.com/questions/75817366/how-to-post-a-tweet-with-geo-data-using-twitter-api-v2-0
- update forums when answer is found:
- helpful tutorials:
- Twitter POST /2/tweets
- Twitter POST /1.1/media/uploads.json
- media-upload.py