Table of Contents
27 Sep 2022
Library resources | |
---|---|
PyPI | https://pypi.org/project/tweepy/ |
Github | https://github.com/tweepy/tweepy |
Homepage | https://www.tweepy.org/ |
Documentation | https://docs.tweepy.org/en/stable/ |
Getting Started
pip3 install tweepy
Usage
import tweepy
# credentials
api_key = os.getenv("TWITTER_API_KEY")
api_secret = os.getenv("TWITTER_API_SECRET")
access_token = os.getenv("TWITTER_ACCESS_TOKEN")
access_token_secret = os.getenv("TWITTER_ACCESS_TOKEN_SECRET")
# authentication of consumer key and secret
auth = tweepy.OAuthHandler(api_key, api_secret)
# authentication of access token and secret
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
text = 'xxx
api.update_status(status=text)
or sending with an image:
api = tweepy.API(auth)
text = 'xxx
image_path = 'path/to/image.jpg'
api.update_status_with_media(text, image_path)