我正在使用Rauth来处理我对Beatport API的请求。以下是我目前的代码。
from rauth import OAuth1Service
beatport = OAuth1Service(
name='beatport',
consumer_key='xxxxxxxxxxxxxx',
consumer_secret='xxxxxxxxxxxxxxxxxx',
request_token_url= 'https://oauth-api.beatport.com/identity/1/oauth/request-token',
access_token_url='https://oauth-api.beatport.com/identity/1/oauth/access-token',
authorize_url='https://oauth-api.beatport.com/identity/1/oauth/authorize',
base_url='https://oauth-api.beatport.com/json/catalog')
request_token, request_token_secret = beatport.get_request_token(method='POST')
print request_token
print request_token_secret
此部分正常工作并打印令牌
authorize_url = beatport.get_authorize_url(request_token)
print authorize_url
这会生成授权URL以及请求令牌。
import urllib
import urllib2
beatport_login = 'login'
beatport_pass = 'pass'
post_string = 'oauth_token='+request_token+'&username='+beatport_login+'&password='+beatport_pass+'&submit=Login'
f = {'https://oauth-api.beatport.com/identity/1/oauth/authorize-submit' : post_string }
g = {'https://oauth-api.beatport.com/identity/1/oauth/request-token?oauth_callback' : 'http://localhost:8000/'}
print urllib.urlencode(f)
print urllib.urlencode(g)
#print('Visit this URL in your browser: {url}'.format(url=authorize_url))
#pin = raw_input('Enter PIN from browser: ')
session = beatport.get_raw_access_token(request_token, request_token_secret, method='POST', data={
'oauth_verifier': pin })
print session
r = session.get('https://oauth-api.beatport.com/catalog/3/tracks?returnFacets=artistName%3AHardwell&perPage=5&sortBy=releaseDate+DESC', params={'format': 'json'})
print r.json()
这是令我困惑的部分。对于会话,我需要一个引脚作为oauth_verifier。根据{{3}},它会附加在我的回调网址的末尾,但我无法理解这些步骤。我如何获得此针?
我正在使用此this answer作为参考。
答案 0 :(得分:0)
我得到了它的工作。我对其余代码做了很多更改,但这里是获取oauth验证程序的代码。
values = {
'oauth_token': request_token,
'username': beatport_login,
'password': beatport_pass,
'submit' : 'Login',
}
r = requests.post('https://oauth-api.beatport.com/identity/1/oauth/authorize-submit', data=values)
verifier = r.url.split("oauth_verifier=",1)[1]
tokens = beatport.get_raw_access_token(request_token, request_token_secret, method='POST', data={
'oauth_verifier': verifier})