Skip to content

Instantly share code, notes, and snippets.

@durgaswaroop
Created December 24, 2017 22:21
Show Gist options
  • Save durgaswaroop/d16cad3f4e3f8d1976a124aac602f5d2 to your computer and use it in GitHub Desktop.
Save durgaswaroop/d16cad3f4e3f8d1976a124aac602f5d2 to your computer and use it in GitHub Desktop.
Tweet with python using tweepy
import tweepy
import os
# Read all the auth keys from environment variables
consumer_key = os.environ["t_consumer_key"]
consumer_secret = os.environ["t_consumer_secret"]
access_token = os.environ["t_access_token"]
access_token_secret = os.environ["t_access_token_secret"]
# Using the keys, setup the authorization
authorization = tweepy.OAuthHandler(consumer_key, consumer_secret)
authorization.set_access_token(access_token, access_token_secret)
# Create the API object
twitter = tweepy.API(auth)
# Text Tweet
twitter.update_status("Tweet using #tweepy")
# Media Tweet
image = os.environ['USERPROFILE'] + "\\Pictures\\cubes.jpg"
twitter.update_with_media(image, "Tweet with media using #tweepy")
#Reply to a Tweet
id_of_tweet_to_reply = "945049796238118912"
twitter.update_status("Reply to a tweet using #tweepy", in_reply_to_status_id=id_of_tweet_to_reply)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment