谷歌播放服務認證(oauth 2.0) (Google play service authentication (oauth 2.0))


問題描述

谷歌播放服務認證(oauth 2.0) (Google play service authentication (oauth 2.0))

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)

參考解法

方法 1:

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:

  • The Google+ Android Quick Start should get you going with a basic implementation.
  • If you have any issues, the most common ones are covered in the Risk Complete Failure blog post Common Problems with Sign‑in on Android
  • If you want to see a full front‑end to back‑end integration, you can look at PhotoHunt
  • The Google+ tag on Stack Overflow tag has up‑to‑date information and support as well

(by quentclass)

參考文件

  1. Google play service authentication (oauth 2.0) (CC BY‑SA 3.0/4.0)

#google-api #google-play-services #Android #google-authentication #google-oauth






相關問題

在 PHP 中壓縮 JSON 字符串並在 Javascript 中解壓縮以進行 Google API 的數據庫查詢 (Compress JSON string in PHP and decompress in Javascript for Database query for Google API)

將 Google Places API 與 MonoTouch 一起使用? (Using Google Places API with MonoTouch?)

如何獲取我的 Gmail 帳戶的個人資料圖片? (How to get the profile picture of my Gmail account?)

google.elements.newsShow 顯示時間不起作用 (google.elements.newsShow display Time not working)

gapi.client.load 未調用回調:console.log 中指定了無效或非法字符串錯誤 (gapi.client.load not calling callback: An invalid or illegal string was specified error in console.log)

Google Developer Console 和已安裝的應用 (Google Developer Console and Installed App)

如何從 Google 自定義搜索 API 獲得 100 多個結果 (How to get more than 100 results from Google Custom Search API)

Pandas / Google Analytics API 身份驗證嘗試給我帶來了一個奇怪的 python 錯誤 (Pandas / Google Analytics API authentication attempt throws me a weird python error)

在 alpha 階段使用谷歌云功能進行生產 (Using a google cloud feature in alpha stage for production)

流量中的 Google Maps Distance Matrix API 持續時間添加返回錯誤結果的所有段 (Google Maps Distance Matrix API duration in traffic adding all segments returning wrong result)

Python 事件集成中的 QML Calendar 和 Google Calendar API (QML Calendar and Google Calendar API in Python events integration)

獲取錯誤 {“error”:“invalid_grant”,“error_description”:“令牌已過期或撤銷。” 來自谷歌 oauth2 API (Getting error { "error" : "invalid_grant", "error_description" : "Token has been expired or revoked." } from Google oauth2 API)







留言討論