我如何可以访问谷歌帐户USER_ID?帐户、USER_ID

2023-09-06 15:33:29 作者:佩服许仙敢曰蛇

我想访问用户的谷歌帐户 USER_ID 了解认证,但我看不出在这个任何提及 的AccountManager

I'd like to access the user's Google account user_id for authentication, but I don't see any mention of this in the AccountManager.

哪有我的应用程序请求 USER_ID

How can my app request the user_id?

推荐答案

现在,谷歌播放服务是可用的,你可以用它来要求用户的访问 https://www.googleapis.com/auth/userinfo.profile 的范围和,用得到的访问令牌,做出 https://www.googleapis.com/oauth2/v1/userinfo?access_token= {}的accessToken 来得到他们的用户ID。

Now that Google Play Services is available, you can use it to request the user's permission to access the https://www.googleapis.com/auth/userinfo.profile scope and, with the resulting access token, make a request to https://www.googleapis.com/oauth2/v1/userinfo?access_token={accessToken} to get their user ID.