Skip to content

Instantly share code, notes, and snippets.

@calistatee
Last active January 27, 2018 01:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calistatee/0636c5d523eeeea5fb1a5e16118e201d to your computer and use it in GitHub Desktop.
Save calistatee/0636c5d523eeeea5fb1a5e16118e201d to your computer and use it in GitHub Desktop.
Python: How to post new status update from your terminal
import tweepy
# log in via codes provided by Twitter
consumer_key = 'enter your consumer key'
consumer_secret = 'enter your consumer secret'
access_token = 'enter your access token'
access_token_secret = 'enter your access token secret'
# this is for authentication by using OAuthHandler and set_access_token method
# from tweepy with a bunch of codes hidden to us
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# main variables where we'll do all the twitter magic
api = tweepy.API(auth)
# if authentication was successful, should be able to see the name
# of my account printed out
print(api.me().name)
# my application settings are set for "Read and Write"
# this line should tweet out my message to my account's timeline
# can’t update duplicate status
api.update_status(status = "Thanks for reading my Data Blog! :)")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment