-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
36 lines (26 loc) · 1.01 KB
/
main.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
29
30
31
32
33
34
35
36
import tweepy
import configparser
CONFIGS = configparser.ConfigParser(interpolation=None)
CONFIGS.read("config.ini")
# Available from Twitter App
consumer_key = CONFIGS["AUTH"]["consumer_key"]
consumer_secret = CONFIGS["AUTH"]["consumer_secret"]
def authenticate():
auth = tweepy.OAuthHandler(consumer_key, consumer_secret, "oob")
try:
url = auth.get_authorization_url()
print("auth url: ", url)
except tweepy.TweepError:
print("Error! Failed to get request token.")
request_token = auth.request_token["oauth_token"]
verifier = input("Verifier:")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.request_token = {"oauth_token": request_token, "oauth_token_secret": verifier}
try:
access_token = auth.get_access_token(verifier)
print("api_key:", access_token[0])
print("api_secret:", access_token[1])
except tweepy.TweepError:
print("Error! Failed to get access token.")
if __name__ == "__main__":
authenticate()