首页 > 解决方案 > 尝试调用 google-api oauth2 时请求缺少所需的身份验证凭据

问题描述

我像这样在邮递员中通过有效负载发送我的 access_token,以在我的后端获取电子邮件、名称等信息。:

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

在后端,我尝试将此 access_token 发送到谷歌请求,如下所示:

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"
      }
    }

我做错了什么?我的 google-access-token 是正确的

标签: pythonpython-3.xgoogle-api

解决方案


推荐阅读