-
Notifications
You must be signed in to change notification settings - Fork 5
/
twitter__login.py
88 lines (61 loc) · 2.61 KB
/
twitter__login.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
import os
import twitter
from twitter.oauth import write_token_file, read_token_file
from twitter.oauth_dance import oauth_dance
def login():
# 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 = ''
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
return twitter.Twitter(domain='api.twitter.com', api_version='1.1',
auth=twitter.oauth.OAuth(oauth_token, oauth_token_secret,
CONSUMER_KEY, CONSUMER_SECRET))
def login_stream():
# 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 = ''
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
return twitter.TwitterStream(
auth=twitter.oauth.OAuth(oauth_token, oauth_token_secret,
CONSUMER_KEY, CONSUMER_SECRET))
def login1():
# 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 = ''
TOKEN_FILE = 'out/twitter.oauth'
try:
(oauth_token, oauth_token_secret) = read_token_file(TOKEN_FILE)
except IOError, e:
(oauth_token, oauth_token_secret) = oauth_dance(APP_NAME, CONSUMER_KEY,
CONSUMER_SECRET)
if not os.path.isdir('out'):
os.mkdir('out')
write_token_file(TOKEN_FILE, oauth_token, oauth_token_secret)
return twitter.Twitter(domain='api.twitter.com', api_version='1',
auth=twitter.oauth.OAuth(oauth_token, oauth_token_secret,
CONSUMER_KEY, CONSUMER_SECRET))
if __name__ == '__main__':
login()