2

我正在尝试使用 OAuth2 来获取使用 Python 到 REST API 的授权令牌。我使用 CURL 成功,但没有使用 python。我正在使用以下文档中提供的示例: https ://requests-oauthlib.readthedocs.org/en/latest/oauth2_workflow.html

以下是我的代码:

#!/usr/bin/python

import requests
import requests_oauthlib
from requests_oauthlib import OAuth2Session
from oauthlib.oauth2 import BackendApplicationClient

client_id = 'AAAAAA'
client_secret = 'BBBBBB'

client = BackendApplicationClient(client_id=client_id)
oauth = OAuth2Session(client=client)
token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)

print token

我收到以下错误:

oauthlib.oauth2.rfc6749.errors.InvalidClientError: (invalid_client)   client_id value doesn't match HTTP Basic username value

这是一个非常基本的 API,只需要 client_id 和 client_credentials 即可获得授权令牌。

所有信息将不胜感激。

4

1 回答 1

0

该文档指定了以下项目:

client_id = r'your_client_id'
client_secret = r'your_client_secret'
redirect_uri = 'https://your.callback/uri'

通过客户端密钥,您可能是指客户端密钥吗?

token = oauth.fetch_token(token_url='https://example.com/as/token.oauth2', client_id=client_id, client_secret=client_secret)

尝试将其更改为上述内容并试一试。使用 r'' 代替原始输入并给出令牌。

于 2016-01-22T20:22:55.377 回答