2012-09-12 48 views

回答

3

现在可以使用Google Play Services,您可以使用它来请求用户访问https://www.googleapis.com/auth/userinfo.profile作用域的权限,并使用生成的访问令牌向https://www.googleapis.com/oauth2/v1/userinfo?access_token={accessToken}发出请求以获取其用户标识。

+0

是'用户信息?access_token = {accessToken}'请求记录在某处? –

+2

此处提供了userinfo的文档:https://developers.google.com/accounts/docs/OAuth2Login#userinfocall –

+0

我[已注意](https://developers.google.com/android/google-play-services/ )'注意:Google Play服务尚未启动,但我们希望快速了解您期望的内容。“这是否意味着API尚不可用,或者它处于某种测试状态? –

1

退房谷歌的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(); 
相关问题