-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOAuth.py
More file actions
36 lines (27 loc) · 1.2 KB
/
OAuth.py
File metadata and controls
36 lines (27 loc) · 1.2 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
# -*- coding: utf-8 -*-
import os
import sys
import twitter
from twitter.oauth import write_token_file, read_token_file
from twitter.oauth_dance import oauth_dance
# Go to http://twitter.com/apps/new to create an app and get these items
# See also http://dev.twitter.com/pages/oauth_single_token
APP_NAME = ''
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
def oauth_login(app_name="Analyzing_Twitter",
consumer_key="1H3NUrvWq1OGuQVh9420Spvld",
consumer_secret="3YmiaPqyiuN00TNlHCKSgLLqfvrFr088nKT7qaukrtZXmZrx9R",
token_file=''):
try:
(access_token, access_token_secret) = read_token_file(token_file)
except IOError as e:
(access_token, access_token_secret) = oauth_dance(app_name, consumer_key,consumer_secret)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(token_file, access_token, access_token_secret)
print (sys.stderr, "OAuth Success. Token file stored to", token_file)
return twitter.Twitter(auth=twitter.oauth.OAuth(access_token, access_token_secret,
consumer_key, consumer_secret))
if __name__ == '__main__':
oauth_login(APP_NAME, CONSUMER_KEY, CONSUMER_SECRET)