尝试调用googleapi oauth2时,请求缺少必需的身份验证凭据

2024-09-25 08:27:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我像这样通过邮递员的有效负载发送我的访问令牌,以获取电子邮件、我后端的姓名等信息:

{
    "access_token": "my-google-acces-token"
}

在后端,我尝试将此访问令牌发送到google请求,如下所示:

response = requests.get('https://www.googleapis.com/oauth2/v2/userinfo',
                        headers={'Authorization': f'Bearer {access_token_data}'})

我得到的回答是:

{
      "error": {
        "code": 401,
        "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
        "status": "UNAUTHENTICATED"
      }
    }

我做错了什么?我的谷歌访问令牌是正确的


Tags: httpscomtoken信息邮递员authenticationaccess电子邮件