我想访问用户的Google帐号user_id
,获取authentication,但在AccountManager
中没有看到任何提及。如何访问Google帐户user_id?
我的应用程序如何请求user_id
?
我想访问用户的Google帐号user_id
,获取authentication,但在AccountManager
中没有看到任何提及。如何访问Google帐户user_id?
我的应用程序如何请求user_id
?
现在可以使用Google Play Services,您可以使用它来请求用户访问https://www.googleapis.com/auth/userinfo.profile
作用域的权限,并使用生成的访问令牌向https://www.googleapis.com/oauth2/v1/userinfo?access_token={accessToken}
发出请求以获取其用户标识。
在Google Play服务发布之前,您需要使用Android AccountManager的getAuthToken API。
这里是你如何使用getAuthToken获得access_token
一个例子:https://stackoverflow.com/a/10988589/313790
退房谷歌的AccountManager example for the Tasks API。
一旦你有一个访问令牌,你再而不是使用任务库,使用谷歌的API的Java客户端的oauth2 library请求Userinfo
对象像this example:
Oauth2 oauth2 = new Oauth2.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
.setApplicationName("Google-OAuth2Sample/1.0").build();
Userinfo userinfo = oauth2.userinfo().get().execute();
String userId = userinfo.getId();
是'用户信息?access_token = {accessToken}'请求记录在某处? –
此处提供了userinfo的文档:https://developers.google.com/accounts/docs/OAuth2Login#userinfocall –
我[已注意](https://developers.google.com/android/google-play-services/ )'注意:Google Play服务尚未启动,但我们希望快速了解您期望的内容。“这是否意味着API尚不可用,或者它处于某种测试状态? –