簡體   English   中英

Google Play服務身份驗證(oauth 2.0)

[英]Google play service authentication (oauth 2.0)

我希望使用oauth2 protocole驗證我的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中),我更改了范圍值。

但是,我無法獲得身份驗證令牌...雖然我已正確配置我的谷歌控制台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服務。

一些資源可以幫助您入門:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM