【问题标题】:Get user's google(gmail profile pic or google+) avatar profile image获取用户的 google(gmail 个人资料图片或 google+)头像个人资料图片
【发布时间】:2018-08-25 13:03:11
【问题描述】:

我猜 Gmail API 没有提供任何获取用户个人资料图片的方法。

我可以使用 Google+ API 获取网址,但我应该有用户的 google+ 用户名。

我只有用户的电子邮件 ID 和他/她的帐户访问令牌 (gmail)。

this question 的答案指向 picasaweb.google.com 托管的网址,该网址现已停用,并且不会返回任何具有 Gsuite 帐户的用户的 emailid 的结果。

【问题讨论】:

    标签: google-api gmail google-plus gmail-api google-plus-signin


    【解决方案1】:

    如果您已对用户进行身份验证。你应该可以使用people.get

    GET https://www.googleapis.com/plus/v1/people/me
    

    回复

    "image": {
      "url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAl1I/UcwPajZOuN4/photo.jpg?sz=50",
      "isDefault": false
     },
    

    这将要求您具有所请求的配置文件范围或其中之一。

    https://www.googleapis.com/auth/plus.login or https://www.googleapis.com/auth/plus.me
    

    还需要用户创建一个 google+ 帐户。不幸的是,这是获取用户头像的唯一方法。

    选项二是链接到谷歌联系人的人员 api,如果他们添加了用户个人资料图片,则可能包括用户个人资料图片。 People.get

    GET https://people.googleapis.com/v1/people/me?personFields=photos
    

    也返回

    "url": "https://lh5.googleusercontent.com/-a1CWlFnA5xE/AAAAAAAAAAI/AAAAAAAAl1I/UcwPajZOuN4/s100/photo.jpg"
    

    【讨论】:

    • @dalmTo 我已经通过 gmail 而不是 google+ 验证了用户
    • @dalmTo 我将无法在我的应用中使用联系人,有没有办法弄清楚如何使用 gmail 端点来做到这一点。
    • 添加另一个 Gmail 端点不包含个人资料信息的范围。只需向用户请求额外的范围
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-06
    相关资源
    最近更新 更多