谷歌游戏服务认证(OAuth的2.0) [英] Google play service authentication (oauth 2.0)

查看:150
本文介绍了谷歌游戏服务认证(OAuth的2.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证我的android应用蒙山的oauth2 protocole的用户,以便用户并不需要创建一个登录名和密码我的应用程序。

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

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

不过,我不设法获得身份验证令牌......虽然我已经正确配置我的谷歌控制台API。

下面的函数调用为gettoken方式:

 保护字符串fetchToken()抛出IOException异常{
      尝试 {
          返回GoogleAuthUtil.getToken(mActivity,mEmail,mScope);
      }赶上(GooglePlayServicesAvailabilityException playEx){
          // GooglePlayServices.apk要么是老了,但禁用或不present。
          mActivity.showErrorDialog(playEx.getConnectionStatus code());
      }赶上(UserRecoverableAuthException userRecoverableException){
          //无法验证,但用户可以解决这个问题。
          //转发用户到适当的活性。
          mActivity.startActivityForResult(userRecoverableException.getIntent(),mRequest code);
      }赶上(GoogleAuthException fatalException){
          onError的(不可恢复的错误+ fatalException.getMessage(),fatalException);
      }
      返回null;
  }
 

和这里是我的范围:观众:服务器:CLIENT_ID:MY_CLIENT_ID.apps.googleusercontent.com

当我尝试了,我得到以下异常:

  08-16 17:22:08.471:E / TokenInfoTask(16546):异常:
08-16 17:22:08.471:E / TokenInfoTask(16546):com.google.android.gms.auth.GoogleAuthException:未知
08-16 17:22:08.471:E / TokenInfoTask(16546):在com.google.android.gms.auth.GoogleAuthUtil.getToken(来源不明)
 

解决方案

您应该使用Google+登录功能,其中谷歌2月份发布的,因为这将让你跨客户端授权和访问更多的数据,您可以使用个性化您的应用程序。在幕后,此授权库使用的OAuth 2连接到谷歌服务。

某些资源,让你开始:

I wish to authenticate users of my android application whith the oauth2 protocole, so as to the user don't need to create a login and password for my app.

To do that, I follow the following tutorial : http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html

I've import the google play service sdk sample (in AndroidSDK\extras\google\google_play_services\samples\auth), and I have change the scope value.

However, I don't manage to get authentication token... While I've correctly configure my google console API.

Here is the function calling getToken method :

  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;
  }

And here is my scope : audience:server:client_id:MY_CLIENT_ID.apps.googleusercontent.com

When I try that, I get the following exceptions :

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)

解决方案

You should be using Google+ Sign-In, which Google released in February, because this will get you cross-client authorization and access to more data that you can use to personalize your app. Behind the scenes, this authorization library uses OAuth 2 to connect to Google services.

Some resources to get you started:

这篇关于谷歌游戏服务认证(OAuth的2.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆