Android Google play服务认证(oauth 2.0)
我希望使用oauth2协议对我的android应用程序的用户进行身份验证,这样用户就不需要为我的应用程序创建登录名和密码 为此,我将遵循以下教程: 我已经导入了google play service sdk示例(在AndroidDK\extras\google\google\U play\U services\samples\auth中),并更改了范围值 但是,我无法获得身份验证令牌。。。虽然我已经正确配置了我的谷歌控制台API 下面是调用getToken方法的函数:Android Google play服务认证(oauth 2.0),android,google-api,google-oauth,google-play-services,google-authentication,Android,Google Api,Google Oauth,Google Play Services,Google Authentication,我希望使用oauth2协议对我的android应用程序的用户进行身份验证,这样用户就不需要为我的应用程序创建登录名和密码 为此,我将遵循以下教程: 我已经导入了google play service sdk示例(在AndroidDK\extras\google\google\U play\U services\samples\auth中),并更改了范围值 但是,我无法获得身份验证令牌。。。虽然我已经正确配置了我的谷歌控制台API 下面是调用getToken方法的函数: protected S
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;
}
这是我的范围:受众:服务器:客户端id:my\u客户端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)
您应该使用谷歌2月份发布的Google+登录,因为这将使您获得跨客户端授权,并访问更多数据,您可以使用这些数据对应用程序进行个性化设置。在幕后,此授权库使用OAuth 2连接到Google服务 让您开始的一些资源:
- 这应该让您开始一个基本的实现
- 如果您有任何问题,最常见的问题将在Risk Complete Failure博客文章中介绍
- 如果希望看到完整的前端到后端集成,可以查看
- 也有最新的信息和支持