Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中从google plus api获取oauth 2.0令牌?_Android_Api_Oauth_Google Plus_Oauth2client - Fatal编程技术网

如何在android中从google plus api获取oauth 2.0令牌?

如何在android中从google plus api获取oauth 2.0令牌?,android,api,oauth,google-plus,oauth2client,Android,Api,Oauth,Google Plus,Oauth2client,我在从google API获取oauth 2.0令牌时遇到问题。我目前正在为android编写应用程序,我希望有三种登录方法——通过facebook(完成)、自定义oauth 2.0提供商(完成)和google plus——这给我带来了很多问题。 我需要在设备上获取访问令牌,并将其进一步传递给后端应用程序 我尝试使用GoogleAppClient(PlusClient不推荐使用-通过 ),但无法看到类似getAccessToken或类似的方法 目前我尝试使用Socialuth库,但由于缺乏文档,

我在从google API获取oauth 2.0令牌时遇到问题。我目前正在为android编写应用程序,我希望有三种登录方法——通过facebook(完成)、自定义oauth 2.0提供商(完成)和google plus——这给我带来了很多问题。 我需要在设备上获取访问令牌,并将其进一步传递给后端应用程序

我尝试使用GoogleAppClient(PlusClient不推荐使用-通过 ),但无法看到类似getAccessToken或类似的方法

目前我尝试使用Socialuth库,但由于缺乏文档,我被卡住了(这里有一些代码)


有人能帮我拿这个代币吗?无论是通过socialauth还是通过GoogleAppClient,这都无关紧要。

关于social auth没有任何线索,但要从Google Play services获得代币,实际上需要使用另一个类GoogleAuthUtil

我把要点放在相关部分:

String scopes = "oauth2:profile email"; // magic string! oauth2: followed by space sep scopes.
String token = null;
try {
    token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
    Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
    startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
    Log.e(TAG, e.getMessage());
}
return token;

帐户名可以从GoogleAppClient Plus获得。帐户API

这正是我需要的!真不敢相信这么简单。非常感谢。
String scopes = "oauth2:profile email"; // magic string! oauth2: followed by space sep scopes.
String token = null;
try {
    token = GoogleAuthUtil.getToken(getApplicationContext(), accountName, scopes);
} catch (IOException e) {
    Log.e(TAG, e.getMessage());
} catch (UserRecoverableAuthException e) {
    startActivityForResult(e.getIntent(), REQ_SIGN_IN_REQUIRED);
} catch (GoogleAuthException e) {
    Log.e(TAG, e.getMessage());
}
return token;