-
Notifications
You must be signed in to change notification settings - Fork 0
/
oauth.py
52 lines (34 loc) · 1.26 KB
/
oauth.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
import json
import urlparse
import urllib
import oauth2 as oauth
## If you're actually processing requests, you'll want this
# import simplejson
request_token_url = 'https://api.dropbox.com/1/oauth/request_token'
authorize_url = 'https://www.dropbox.com/1/oauth/authorize'
access_token_url = 'https://api.dropbox.com/1/oauth/access_token'
### GET A REQUEST TOKEN ###
consumer = oauth.Consumer(key="YOURKEYHERE", secret="YOURSECRETHERE")
client = oauth.Client(consumer)
response = client.request(request_token_url, "GET")[1]
request_token = dict(urlparse.parse_qsl(response))
token = oauth.Token(
request_token['oauth_token'],
request_token['oauth_token_secret']
)
# AUTHORIZE
print 'Please go to %s?oauth_token=%s' % (authorize_url, request_token['oauth_token'])
raw_input('OK ?')
# ACCESS TOKEN
token = oauth.Token(request_token['oauth_token'],
request_token['oauth_token_secret'])
#token.set_verifier()
client = oauth.Client(consumer, token)
resp, content = client.request(access_token_url, "POST")
access_token = dict(urlparse.parse_qsl(content))
token = oauth.Token(
access_token['oauth_token'],
access_token['oauth_token_secret']
)
client = oauth.Client(consumer, token)
print client.request('https://api.dropbox.com/1/metadata/sandbox/', 'GET')