【问题标题】:Google AccountManager AndroidGoogle AccountManager Android
【发布时间】:2011-12-13 02:38:25
【问题描述】:

我一直在试图弄清楚如何使用 Google 客户经理来简单地为用户提供一种登录我的应用的方式。

我返回了 AuthToken,但我如何才能获得一些不会更改的帐户的唯一信息,例如唯一 ID 或其他东西,以便我可以使用它来登录用户?

【问题讨论】:

    标签: android accountmanager


    【解决方案1】:

    您从AccountManager 获得的Account 对象有一个name 字段,它是用户的电子邮件地址。这应该是唯一的,因为它们都由 Google 管理并且需要密码才能设置。

    根据获取 AuthToken 时请求的权限,可以查询端点https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=YourTokenHere 并获取有关该帐户的一堆信息。

    响应将如下所示:

    {
     "id": "1234567890",
     "email": "joseph.mother@gmail.com",
     "verified_email": true,
     "name": "Joe Mama",
     "given_name": "Joe",
     "family_name": "Mama",
     "link": "https://plus.google.com/1234567890",
     "picture": "https://lh6.googleusercontent.com/-abcd/abcd/abcd/1234/photo.jpg",
     "gender": "male",
     "locale": "en"
    }
    

    这里的id 字段也是独一无二的,并且可以在所有 Google 服务中使用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2011-10-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多