-
Go to https://developer.twitter.com/en/portal/projects-and-apps
-
Once you enter the app screen, create a new "development" app:
-
Once you get to the "Keys & Tokens" section, make sure that you copy and store the API Key and API Secret Key in a safe place. You will need them to authenticate with the TwitterBot class.
-
Then click "App Settings" -> then "Keys and Tokens." On this page you will need to generate an access token and access token secret. You will need these as well to authenticate with the TwitterBot class.
from twitter_bot import TwitterBot
# Create a TwitterBot object
bot = TwitterBot(
api_key="YOUR_TWITTER_API_KEY",
api_secret_key="YOUR_TWITTER_API_SECRET_KEY",
access_token="YOUR_TWITTER_ACCESS_TOKEN",
access_token_secret="YOUR_TWITTER_ACCESS_TOKEN_SECRET"
)
# Post a tweet
bot.post_tweet("Hello World!")
# Post a tweet with tags:
bot.post_tweet("Hello World!", tags=["bot", "python"])
# Post a tweet with an image:
bot.post_tweet("Hello World!", media_filepath="path/to/image.jpg")