我正在开发一个使用 Google 进行身份验证的 Android 应用程序。我们获取令牌以验证用户身份的代码如下,遵循“auth”示例 Android 项目的 GetNameInForeground.java:
/**
* Get a authentication token if one is not available. If the error is not recoverable then
* it displays the error message on parent activity right away.
*/
@Override
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (GooglePlayServicesAvailabilityException playEx) {
// GooglePlayServices.apk is either old, disabled, or not present.
mActivity.showErrorDialog(playEx.getConnectionStatusCode());
} catch (UserRecoverableAuthException userRecoverableException) {
// Unable to authenticate, but the user can fix this.
// Forward the user to the appropriate activity.
onError("Authorization problem with Google account", userRecoverableException);
//mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
} catch (GoogleAuthException fatalException) {
onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
}
return null;
}
登录时,我们经常收到错误“Unrecoverable error unknown”。这表明我们从调用 GoogleAuthUtil.getToken 中得到了 fatalExceptions,但我们不知道为什么。http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html没有提供太多有关错误消息的信息。