-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauth.py
28 lines (24 loc) · 823 Bytes
/
auth.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import tweepy
from utils.env_util import getEnv
def authenticate():
# Getting the tokens and keys
environ_secrets = getEnv()
# Setting up variables
consumer_key = environ_secrets[0]
consumer_secret = environ_secrets[1]
access_token = environ_secrets[2]
access_token_secret = environ_secrets[3]
# Creating Auth object
auth = tweepy.OAuthHandler(consumer_key=consumer_key, consumer_secret=consumer_secret)
# Setting access token to access API
auth.set_access_token(access_token, access_token_secret)
# Getting the API object to make API calls
api = tweepy.API(auth)
# Verifying API and returning the API object
try:
api.verify_credentials()
print("Verified")
return api
except:
print("Wrong Credentials")
return None