googleoauth获取用户emai

2024-04-25 08:20:39 发布

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

我使用Flask-dance来验证用户身份(使用Google作为身份验证提供者),我尝试获取用户的电子邮件,尝试了几个选项-没有人返回了电子邮件。你知道吗

代码片段:(谷歌是高射炮弹舞谷歌蓝图)

   if not google.authorized:
            return redirect(url_for("google.login"))
   else:
       resp = google.get(url)

我尝试了以下URL:

  1. https://openidconnect.googleapis.com/v1/userinfo

  2. https://www.googleapis.com/auth/userinfo.email

  3. https://www.googleapis.com/oauth2/v3/userinfo

  4. https://www.googleapis.com/oauth2/v3/tokeninfo

在创建Google蓝图时,我正在使用作用域:scope=["profile", "email"]。我得到的数据结构是:

{'sub': 'XYZ', 'name': 'XYZ', 'given_name': 'XYZ',
 'family_name': 'XYZ', 'picture': 'XYZ', 'locale': 'XYZ'}

在第https://console.cloud.google.com/apis/credentials/consent页的“OAuth同意屏幕”页的“谷歌API的作用域”部分下,我有以下条目:

  • 电子邮件
  • 简介
  • 开放ID

我的问题是:

如何获取用户电子邮件上的字段?你知道吗

谢谢


Tags: 用户namehttpscomurl电子邮件emailwww