问题描述
我一直在试图找出如何使用谷歌的客户经理简单地提供一个方法让用户登录到我的应用程序。
I've been trying to figure out how to use the Google account manager to simply provide a way for users to Login to my app.
我有回来的authToken,但我怎么能得到不会改变例如UNIQUEID什么的,这样我可以用它来登录的用户帐户一些独特的信息?
I have the AuthToken returning, but how can I get some unique info on the account that won't change for example a uniqueID or something so that I can use it to login the user?
推荐答案
在帐户
从的AccountManager
获取对象有一个名称
字段,它是用户的电子邮件地址。这应该是独一无二的,因为它们都是由谷歌管理,需要密码才能成立。
The Account
object you get from AccountManager
has a name
field which is the user's email address. This should be unique since they are all managed by Google and require a password to set up.
根据你要求得到的authToken的时候,你可以查询端点 https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=YourTokenHere 并取回了一堆有关帐户的信息。
Depending on what permissions you asked for when getting the AuthToken, you can query the endpoint https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=YourTokenHere
and get back a bunch of information about the account.
的回应将是这个样子:
{
"id": "1234567890",
"email": "[email protected]",
"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
字段这里也是独特的,具有跨谷歌服务所使用的奖金。
The id
field here is also unique and has the bonus of being used across Google services.
这篇关于谷歌的Android的AccountManager的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!