Oauth2 en python :
print 'Visit https://bitcoin-central.net/api/oauth/authorize?client_id=' + CLIENT_ID + '&redirect_uri=https%3A%2F%2Fbitcoin-central.net%2Fpage%2Foauth%2Ftest&response_type=code&scope=basic+activity'
code = raw_input('Paste the code : ')
values = {'client_id' : CLIENT_ID,
'client_secret' : CLIENT_SECRET,
'grant_type' : 'authorization_code',
'redirect_uri' : 'https://bitcoin-central.net/page/oauth/test',
'code' : code}
data = urllib.urlencode(values)
req = urllib2.Request(OAUTH_URL, data)
httpData= urllib2.urlopen(req).read()
token = json.loads(httpData)
refresh_token = json.dumps(token["refresh_token"]).strip('"')
tt_left = int(json.dumps(token["expires_in"]))
token = json.dumps(token["access_token"]).strip('"')
while(1):
before = time.time()
if (tt_left < 100):
values = {'client_id' : CLIENT_ID,
'client_secret' : CLIENT_SECRET,
'grant_type' : 'authorization_code',
'redirect_uri' : 'https://bitcoin-central.net/page/oauth/test',
'code' : code}
data = urllib.urlencode(values)
req = urllib2.Request(OAUTH_URL, data)
httpData= urllib2.urlopen(req).read()
token = json.loads(httpData)
refresh_token = json.dumps(token["refresh_token"]).strip('"')
tt_left = int(json.dumps(token["expires_in"]))
token = json.dumps(token["access_token"]).strip('"')
while(1):
before = time.time()
if (tt_left < 100):
values = {'client_id' : CLIENT_ID,
'client_secret' : CLIENT_SECRET,
'grant_type' : 'refresh_token',
'redirect_uri' : 'https://bitcoin-central.net/page/oauth/test',
'refresh_token' : refresh_token}
data = urllib.urlencode(values)
req = urllib2.Request(OAUTH_URL, data)
httpData= urllib2.urlopen(req).read()
token = json.loads(httpData)
refresh_token = json.dumps(token["refresh_token"]).strip('"')
tt_left = int(json.dumps(token["expires_in"]))
token = json.dumps(token["access_token"]).strip('"')
opener = urllib2.build_opener()
opener.addheaders = [('Authorization', ' Bearer '+ token)]
httpData = opener.open(USER_URL).read()
user_data = json.loads(httpData)
httpData = opener.open(ORDERS_URL).read()
orders_data = json.loads(httpData)
#SNIP
time.sleep(20)
after = time.time()
tt_left = tt_left + (before - after)
Finalement pas si compliqué que ça, même si ça oblige juste à avoir un navigateur sous la main...