1

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

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

4

1 回答 1

2

Account您从中获取的对象AccountManager有一个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 服务中使用。

于 2011-12-12T18:38:25.843 回答