【发布时间】:2013-08-16 15:41:04
【问题描述】:
我希望使用 oauth2 协议对我的 android 应用程序的用户进行身份验证,以便用户无需为我的应用程序创建登录名和密码。
为此,我遵循以下教程:http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html
我已经导入了 google play service sdk 示例(在 AndroidSDK\extras\google\google_play_services\samples\auth 中),并且我已经更改了范围值。
但是,我无法获得身份验证令牌...虽然我已经正确配置了我的 google 控制台 API。
这里是调用getToken方法的函数:
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.
mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
} catch (GoogleAuthException fatalException) {
onError("Unrecoverable error " + fatalException.getMessage(), fatalException);
}
return null;
}
这是我的范围:audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com
当我尝试这样做时,我得到以下异常:
08-16 17:22:08.471: E/TokenInfoTask(16546): Exception:
08-16 17:22:08.471: E/TokenInfoTask(16546): com.google.android.gms.auth.GoogleAuthException: Unknown
08-16 17:22:08.471: E/TokenInfoTask(16546): at com.google.android.gms.auth.GoogleAuthUtil.getToken(Unknown Source)
【问题讨论】:
标签: android google-api google-oauth google-play-services google-authentication