【发布时间】:2021-11-10 17:50:39
【问题描述】:
我在使用 python 从 oauth2 平台获取访问令牌时遇到问题。
目前,这就是我在发帖请求中使用的内容:
def token(self):
client_id=ID_DO_CLIENTE
client_secret=SECRET_TOKEN
grant_type='client_credentials'
response = requests.post("https://oauth2.googleapis.com/token",
auth=(client_id, client_secret),
data={'grant_type':grant_type,'client_id':client_id,'client_secret':client_secret})
print(response.text)
此特定代码返回以下错误:
{
"error": "unsupported_grant_type",
"error_description": "Invalid grant_type: "
}
但我认为问题不在于 grant_type,因为我已经尝试了我在网上找到的所有方法来解决这个问题。
无论如何,如果缺少任何信息,请告诉我。请帮忙!
【问题讨论】:
-
您正在使用
auth,它用于基本身份验证。试试这个:stackoverflow.com/a/36737820/16912753 -
我已经尝试了这两种方法,但不幸的是没有成功。但刚才我意识到了一些事情:我的应用程序应该从服务器发出简单的请求,而不是对用户进行身份验证。我处理这个问题的方式有什么不同吗?
标签: python oauth-2.0 python-requests google-oauth refresh-token