1

我想验证我的Android应用程序的用户与oauth2 protocole,以便用户不需要为我的应用程序创建一个登录名和密码。谷歌播放服务认证(oauth 2.0)

为了做到这一点,我按照下面的教程:http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html

我已经导入谷歌播放服务SDK示例(在AndroidSDK \演员\谷歌\ google_play_services \ SAMPLES \ AUTH),我有改变的范围值。

但是,我无法获得身份验证令牌...虽然我已正确配置我的谷歌控制台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) 

回答

3

你应该使用谷歌2月份发布的Google+登录功能,因为这会让您获得跨客户端授权并访问更多可用于个性化设置的数据你的应用。在幕后,此授权库使用OAuth 2连接到Google服务。

一些资源,让你开始:

+0

感谢您的建议,但使用Google+登录,用户必须点击一个按钮,而与谷歌播放服务认证他不' t需要... – juzamn

+0

从何时起,GoogleAuthUtil.getToken()方法开始抛出一个带有消息的GoogleAuthException“ BadUsername“用于未在设备上注册的电子邮件,而不是以前的异常IllegalArgumentException,并显示消息”Non existing account'email_address'“? http://developer.android.com/reference/com/google/android/gms/auth/GoogleAuthUtil.html#getToken(android.content.Context,java.lang.String,java.lang.String) – toobsco42

+0

请求用户信息.profile和plus.login将导致此异常。请从您的请求中移除userinfo.profile范围。 – class