【问题标题】:How do I get the oauth_verifier for a session in Rauth如何在 Rauth 中获取会话的 oauth_verifier
【发布时间】:2013-12-14 11:15:02
【问题描述】:

我使用 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。根据this answer,它将附加在我的回调 URL 的末尾,但我无法理解这些步骤。我如何得到这个别针?

我使用这个working example in PHP 作为参考。

【问题讨论】:

    标签: php python api oauth rauth


    【解决方案1】:

    我让它工作了。我对其余代码做了很多更改,但这里是获取 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})
    

    【讨论】:

      猜你喜欢
      • 2017-11-15
      • 2013-04-20
      • 2014-08-13
      • 1970-01-01
      • 2013-12-11
      • 2012-09-04
      • 2013-05-24
      • 2017-07-28
      • 1970-01-01
      相关资源
      最近更新 更多