Skip to content

Instantly share code, notes, and snippets.

@mattccrampton
Last active November 4, 2017 05:39
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 mattccrampton/dfc194e4a865e2c534d04cd13212056d to your computer and use it in GitHub Desktop.
Save mattccrampton/dfc194e4a865e2c534d04cd13212056d to your computer and use it in GitHub Desktop.
Tweet from python using tweepy
import tweepy
def get_api(cfg):
auth = tweepy.OAuthHandler(cfg['consumer_key'], cfg['consumer_secret'])
auth.set_access_token(cfg['access_token'], cfg['access_token_secret'])
return tweepy.API(auth)
def main():
# Fill in the values noted in previous step here
cfg = {
"consumer_key" : "REPLACE_THIS_WITH_YOUR_CONSUMER_KEY",
"consumer_secret" : "REPLACE_THIS_WITH_YOUR_CONSUMER_SECRET",
"access_token" : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN",
"access_token_secret" : "REPLACE_THIS_WITH_YOUR_ACCESS_TOKEN_SECRET"
}
api = get_api(cfg)
tweet = "Another day, another #scifi #book and a cup of #coffee"
status = api.update_status(status=tweet)
# Yes, tweet is called 'status' rather confusing
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment