-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthentication.py
More file actions
39 lines (31 loc) · 1.41 KB
/
authentication.py
File metadata and controls
39 lines (31 loc) · 1.41 KB
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
37
38
39
import tweepy
import botometer
import webbrowser
def authenticateOnTwitterWithToken(consumer_key, consumer_secret, token_key, token_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, compression=True)
try:
api.verify_credentials()
print("Authentication ok!")
except:
print("Error during authentication")
exit()
return api
def authenticateOnTwitterWithoutToken(consumer_key, consumer_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth_url = auth.get_authorization_url()
print("Vou abrir uma janela do seu navegador. Logue-se por ela no Twitter, autorize o uso desse app.")
webbrowser.open(auth_url)
verify_code = input("Digite o código de verificação informado pelo Twitter > ")
auth.get_access_token(verify_code)
api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True, compression=True)
try:
api.verify_credentials()
print("Authentication ok!")
except:
print("Error during authentication")
exit()
return api, auth.access_token, auth.access_token_secret
def authenticateOnBotometer(rapidapi_key, twitter_app_auth):
return botometer.Botometer(wait_on_ratelimit=True, rapidapi_key=rapidapi_key, **twitter_app_auth)