我正在尝试使用 lyft 开发者 API。我创建了一个新应用程序来获取客户端 ID 和客户端密码。我正在按照https://developer.lyft.com/docs/authentication中的步骤在我的 python 代码中获取访问令牌。但我总是得到错误,“未经授权的客户”。谁能指出我的错误?
def __init__(self):
self.client_id = 'MY_ID'
self.client_secret = 'MY_SECRET'
# obtain access token
self.token = self.__generate_token__()
# define variables to be used in the request parameters
token_val = 'Bearer '+self.token
self.headers = {'Authorization':token_val}
def __generate_token__(self):
url = 'https://api.lyft.com/oauth/token'
# define request parameters
payload = {"Content-Type": "application/json",
"grant_type": "client_credentials",
"scope": "public"}
# request data
res = requests.post(url,
data = payload,
auth = (self.client_id, self.client_secret))
# extract the token from the response
token = res.json()['access_token']
return token