android - Google play服务认证(oauth 2.0)

标签 android google-api google-oauth google-play-services google-authentication

我希望使用 oauth2 协议(protocol)对我的 android 应用程序的用户进行身份验证,这样用户就不需要为我的应用程序创建登录名和密码。

为此,我遵循以下教程:http://android-developers.blogspot.fr/2013/01/verifying-back-end-calls-from-android.html

我导入了 google play 服务 sdk 示例(在 AndroidSDK\extras\google\google_play_services\samples\auth 中),并且更改了范围值。

但是,我无法获得身份验证 token ...虽然我已经正确配置了我的 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)

最佳答案

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

一些帮助您入门的资源:

关于android - Google play服务认证(oauth 2.0),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18277214/

相关文章:

HTML 页面不显示谷歌地图

php - JWT 和 PHP 的问题

oauth - Google 身份服务之间的关系 - 使用 Google 登录和 Google API 的用户授权

android - 从android中的数据库查询构造对象

android - 在不耗尽电池的情况下保持服务清醒

android - 自定义视频录制方向

ios - iOS 上的 Google Places AutoComplete - 无法加载搜索结果 - 再试一次

Android 致命异常 : java. lang.NoClassDefFoundError:解析失败:Lorg/apache/http/RequestLine;

python - HTTP 错误 400 错误请求(其他类似问题对我没有帮助)

c# - MVC 中的 GoogleWebAuthorizationBroker For Google Drive Access