【发布时间】:2013-10-04 23:19:17
【问题描述】:
我有安卓、谷歌授权问题(类似于.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) 获取访问令牌
- activity != null,client_id = 123456789.apps.googleusercontent.com,accountName 是有效的电子邮件(使用帐户选择器选择)
- http://plus.google.com/u/0/apps 中的帐户名称有关于我的项目的记录: -------- 应用和购买活动--------您的圈子
- 我有
android.permission.GET_ACCOUNTS - appActivities.putString(GoogleAuthUtil.KEY_REQUEST_VISIBLE_ACTIVITIES, "") 的相同异常
- 与 GoogleAuthUtil.getToken(activity, accountName, scopes) 相同的异常
已解决
- 您应该有 2 个客户端 ID:已安装的应用程序 (Android) 和服务 1。您应该在这里使用服务一。
- 然后你会得到 UserRecoverableAuthException: NeedPermission。你应该处理异常
即像这样:
} catch (UserRecoverableAuthException e) {
activity.startActivityForResult(e.getIntent(), REQUEST_AUTHORIZATION);
}
【问题讨论】:
-
嗯,我很确定以“oauth2:”开头的版本是正确的。您能否从异常中获取消息,或者查看 logcat?
-
从什么时候开始,GoogleAuthUtil.getToken() 方法开始为未在设备上注册的电子邮件抛出带有消息“BadUsername”的 GoogleAuthException,而不是之前带有消息“Non existing account”的异常 IllegalArgumentException '电子邮件地址'” ? developer.android.com/reference/com/google/android/gms/auth/…, java.lang.String, java.lang.String)
-
“服务一号”是什么意思?我可以从开发者控制台获取它吗?
标签: android google-oauth