我有 android、google 授权问题(类似于.GoogleAuthException: Unknown while doing Google SSO。-没有答案):
09-29 00:04:38.328: W/System.err(15623): com.google.android.gms.auth.GoogleAuthException: Unknown
09-29 00:04:38.328: W/System.err(15623): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
当我执行以下代码时,它是可重现的:
String scopesString = Scopes.PLUS_LOGIN + " " + Scopes.PLUS_PROFILE;
String scopes = "oauth2:server:client_id:" + Consts.GOOGLE_PLUS_SERVER_CLIENT_ID + ":api_scope:" + scopesString;
OR
String scopes = "audience:server:client_id:" + Consts.GOOGLE_PLUS_SERVER_CLIENT_ID;
Bundle appActivities = new Bundle();
appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "http://schemas.google.com/AddActivity http://schemas.google.com/BuyActivity");
GoogleAuthUtil.getToken(activity, accountName, scopes, appActivities);
以下是一些注意事项:
- 我可以使用 GoogleAuthUtil.getToken(activity, accountName, "oauth2:" + scopesString) 获取访问令牌
- 活动!= null,client_id = 123456789.apps.googleusercontent.com,accountName 是有效的电子邮件(使用帐户选择器选择)
- http://plus.google.com/u/0/apps中的accountName有关于我的项目的记录:<Project Name> -------- 应用和购买活动--------您的圈子
- 我有
android.permission.GET_ACCOUNTS
- appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "") 的相同异常
- 与 GoogleAuthUtil.getToken(activity, accountName, scopes) 相同的异常
解决了
- 您应该有 2 个客户端 ID:已安装的应用程序 (Android) 和服务一。您应该在这里使用服务一。
- 然后你会得到 UserRecoverableAuthException: NeedPermission。你应该处理异常
即像这样:
} catch (UserRecoverableAuthException e) {
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}