oauth.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from __future__ import absolute_import, print_function
  2. import tweepy
  3. # == OAuth Authentication ==
  4. #
  5. # This mode of authentication is the new preferred way
  6. # of authenticating with Twitter.
  7. # The consumer keys can be found on your application's Details
  8. # page located at https://dev.twitter.com/apps (under "OAuth settings")
  9. consumer_key=""
  10. consumer_secret=""
  11. # The access tokens can be found on your applications's Details
  12. # page located at https://dev.twitter.com/apps (located
  13. # under "Your access token")
  14. access_token=""
  15. access_token_secret=""
  16. auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
  17. auth.secure = True
  18. auth.set_access_token(access_token, access_token_secret)
  19. api = tweepy.API(auth)
  20. # If the authentication was successful, you should
  21. # see the name of the account print out
  22. print(api.me().name)
  23. # If the application settings are set for "Read and Write" then
  24. # this line should tweet out the message to your account's
  25. # timeline. The "Read and Write" setting is on https://dev.twitter.com/apps
  26. api.update_status(status='Updating using OAuth authentication via Tweepy!')