-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathconnect.py
More file actions
47 lines (35 loc) · 1.58 KB
/
connect.py
File metadata and controls
47 lines (35 loc) · 1.58 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
45
46
47
from requests_oauthlib import OAuth1Session
import webbrowser
request_token_url = 'http://api.musescore.com/oauth/request_token'
base_authorization_url = 'http://musescore.com/oauth/authorize'
access_token_url = 'http://api.musescore.com/oauth/access_token'
client_key = 'musichackday'
client_secret='musichackday2013'
resource_owner_key=''
resource_owner_secret=''
#obtain a request token
oauth = OAuth1Session(client_key, client_secret=client_secret)
fetch_response = oauth.fetch_request_token(request_token_url)
print fetch_response
resource_owner_key = fetch_response.get('oauth_token')
resource_owner_secret = fetch_response.get('oauth_token_secret')
# Obtain authorization
authorization_url = oauth.authorization_url(base_authorization_url)
print 'Please go here and authorize,', authorization_url
webbrowser.open(authorization_url)
redirect_response = raw_input('Press any key when authorized')
# Obtain access token
oauth = OAuth1Session(client_key,
client_secret=client_secret,
resource_owner_key=resource_owner_key,
resource_owner_secret=resource_owner_secret)
oauth_tokens = oauth.fetch_access_token(access_token_url)
print oauth_tokens
resource_owner_key = oauth_tokens.get('oauth_token')
resource_owner_secret = oauth_tokens.get('oauth_token_secret')
cred = {"client_key": client_key, "client_secret": client_secret,
"resource_owner_key": resource_owner_key,
"resource_owner_secret": resource_owner_secret}
import json
with open('credentials.json', 'w') as outfile:
json.dump(cred, outfile)