我正在尝试使用Oauth2来验证我的设备中登录的Google用户。我已经创建了客户端ID,但我无法获得预期的结果。
代码是:
String mScope="oauth2:server:client_id:NNNNNNNNNNN.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login";
protected Void doInBackground(String... accountName) {
Log.i("Inside on AsynTask:","I am here");
String accName=accountName[0];
try {
token1 = GoogleAuthUtil.getToken(Web_view_demo.this,
accName,
mScope);
Log.i("Inside on AsynTask:","I am here");
} catch (IOException transientEx) {
// Network or server error, try later
Log.e("IO", transientEx.toString());
} catch (UserRecoverableAuthException e) {
// Recover (with e.getIntent())
Log.e("UserRecover", e.toString());
//Intent recover = e.getIntent();
//startActivityForResult(recover, 1);
} catch (GoogleAuthException authEx) {
// The call is not ever expected to succeed
// assuming you have already verified that
// Google Play services is installed.
Log.e("GoogleAuth", authEx.toString());
}
Log.i("Token:",token1);
return null;
}
错误是:
com.google.android.gms.auth.GoogleAuthException: Unknown
非常感谢。
谢谢。
答案 0 :(得分:2)
对我来说,下面的范围格式有效:
String mScope="oauth2:server:client_id:123456789-dgrgfdgfdgfdgngemhmtfko16f5tnobqphb6v.apps.googleusercontent.com:api_scope:https://www.googleapis.com/auth/plus.login"
除此之外如果您错过了针对您的应用在开发人员控制台中设置的同意屏幕,您最终可能会遇到此GoogleAuth异常:未知。
答案 1 :(得分:0)
另外,请确保在Google Developer Console中启用了您的应用ID:API中的https://console.developers.google.com/& Auth,Credentials,OAuth 2.0客户端ID,Android客户端。