Skip to content

Instantly share code, notes, and snippets.

@svmotha
Last active June 11, 2017 03: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 svmotha/ae8f3b8e09ca30f7f7571c50e6efb9c3 to your computer and use it in GitHub Desktop.
Save svmotha/ae8f3b8e09ca30f7f7571c50e6efb9c3 to your computer and use it in GitHub Desktop.
Tweepy twitter authentication with 'secret' twitter keys import.
import tweepy
from keyStorage.keys import keys
class apiConnect():
def __init__(self, **kwargs):
self.__dict__.update(kwargs)
# Authenticate user credentials and get access to twitter API
def authentication(self):
# Use user keys
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_KEY = keys['access_token']
ACCESS_SECRET = keys['access_token_secret']
# Authenticate twitter account credentials using tweepy
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
# Set access keys for authenticated user
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
# Set twitter API through tweepy and return api
api = tweepy.API(auth, retry_count=5,
retry_errors=None, timeout=120, compression=False)
return api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment