dongtou2016 2019-01-22 12:04
浏览 30
已采纳

如何通过PHP安全地检索谷歌用户ID?

I'm trying to set up a system that a user could sign up through google sign-in and I need a detail about a user that will always be constant. I figured that would be the ID, but that's pretty much the only detail I can't get through PHP.

I can get the details about a user using a token ID and it would return this.

"iss": "https://accounts.google.com",
 "sub": "110169484474386276334",
 "azp": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
 "aud": "1008719970978-hb24n2dstb40o45d4feuo2ukqmcc6381.apps.googleusercontent.com",
 "iat": "1433978353",
 "exp": "1433981953",

 // These seven fields are only included when the user has granted the "profile" and
 // "email" OAuth scopes to the application.
 "email": "testuser@gmail.com",
 "email_verified": "true",
 "name" : "Test User",
 "picture": "https://lh4.googleusercontent.com/-kYgzyAWpZzJ/ABCDEFGHI/AAAJKLMNOP/tIXL9Ir44LE/s99-c/photo.jpg",
 "given_name": "Test",
 "family_name": "User",
 "locale": "en"

But I can't find a detail that would be unique and constant so I can see if their account already exists. Is there something else I could use or can I retrieve the ID of a user through php?

  • 写回答

1条回答 默认 最新

  • douxie7339 2019-01-22 12:39
    关注

    I'm not sure about the labels above or where you got them, but looking at the values (and comparing them to my own collection of Gmail User IDs from Oauth), the sub value is the user ID field.

    Counterintuitively, email is not unique, as in one account can have several email aliases, and you can change email addresses on an account.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料