簡體   English   中英

在 Android 上使用 Google Play 服務的 OAuth2 令牌

[英]OAuth2 token with google play services on Android

我正在嘗試使用 Google Play 服務為 Android 上的 Google Cloud Storage 獲取 Oauth2 令牌。 我正在使用以下代碼

try {
        gsToken=GoogleAuthUtil.getToken(this, email,
            "https://www.googleapis.com/auth/devstorage.read_only");
    } catch (IOException e) {
        e.printStackTrace();
    } catch (UserRecoverableAuthException userAuthEx) {
            startActivityForResult(userAuthEx.getIntent(),1);;
    } catch (GoogleAuthException e) {

    }

這會引發 GoogleAuthException。 Google PLAy 服務目前不支持此范圍嗎??

在向 GoogleAuthUtil 詢問 OAuth2 令牌時,您需要使用字符串“oauth2:”作為范圍的前綴。 如果您想要多個范圍,您可以使用空格分隔符列出它們。

因此,在您的情況下,范圍字符串將是“oauth2:https://www.googleapis.com/auth/devstorage.read_only”。

有關更多詳細信息,請參閱http://android-developers.blogspot.com/2012/09/google-play-services-and-oauth-identity.html

暫無
暫無

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

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