【问题标题】:Google oauth - getting the user emailGoogle oauth - 获取用户电子邮件
【发布时间】:2019-12-22 14:57:29
【问题描述】:

我正在使用 Flask dance 来验证用户身份(使用 Google 作为身份验证提供者)我尝试获取用户电子邮件并尝试了几个选项 - 他们都没有返回电子邮件。

代码 sn-p:(google is flak-dance Google blue print)

   if not google.authorized:
            return redirect(url_for("google.login"))
   else:
       resp = google.get(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 同意屏幕”页面的“Google API 范围”部分下,我有以下条目:

  • 电子邮件
  • 个人资料
  • openid

我的问题是:

我如何获得上面的字段用户的电子邮件?

谢谢

【问题讨论】:

    标签: python oauth-2.0 google-oauth flask-dance


    【解决方案1】:

    这是我获取用户电子邮件的方式:(加上其他一些字段)

    https://www.googleapis.com/oauth2/v2/userinfo?fields=id,email,name,picture

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-07
      • 1970-01-01
      • 2021-06-02
      • 2023-03-09
      • 2015-05-11
      相关资源
      最近更新 更多