-
Notifications
You must be signed in to change notification settings - Fork 38
Expand file tree
/
Copy pathoauth.py
More file actions
45 lines (33 loc) · 1.26 KB
/
oauth.py
File metadata and controls
45 lines (33 loc) · 1.26 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
40
41
42
43
44
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import human_curl as hurl
from human_curl.auth import BasicAuth, DigestAuth, OAuthManager, OAuthConsumer, OAuthToken
def stdout_debug(debug_type, debug_msg):
"""Print messages
"""
debug_types = ('I', '<', '>', '<', '>')
if debug_type == 0:
print('%s' % debug_msg.strip())
elif debug_type in (1, 2):
for line in debug_msg.splitlines():
print('%s %s' % (debug_types[debug_type], line))
elif debug_type == 4:
print('%s %r' % (debug_types[debug_type], debug_msg))
CONSUMER_KEY = ""
CONSUMER_SECRET = ""
REQUEST_TOKEN_URL = "https://api.twitter.com/oauth/request_token"
AUTHORIZE_URL = "https://api.twitter.com/oauth/authorize"
ACCESS_TOKEN_URL = "https://api.twitter.com/oauth/access_token"
CALLBACK_URL = "http://h.wrttn.me/request_callback"
ACCESS_TOKEN = ""
ACCESS_TOKEN_SECRET = ""
PROTECTED_RESOURCE = "https://api.twitter.com/1/statuses/home_timeline.json?count=5"
consumer = OAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET)
token = OAuthToken(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
oauth = OAuthManager(consumer, token)
r = hurl.get(PROTECTED_RESOURCE,
debug=stdout_debug,
allow_redirects=False,
auth=oauth)
print(r)
print(r.content)