2

我正在使用 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()

这是让我感到困惑的部分。对于会话,我需要一个 pin 作为 oauth_verifier。根据这个答案,它将附加在我的回调 URL 的末尾,但我无法理解这些步骤。我如何得到这个别针?

在 PHP 中使用这个工作示例作为参考。

4

1 回答 1

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})
于 2013-12-06T18:57:52.440 回答