2

我試圖使用Google Play服務在Android上爲Google雲端存儲獲取Oauth2令牌。我正在使用以下代碼在Android上使用Google Play服務的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 Services此時不支持此範圍嗎?

回答

2

當向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

+0

嘿@jham,這個用於爲我工作,但僅僅在幾天前它停止工作,現在它引發了這個錯誤com.google.android.gms.auth.GoogleAuthException:Unknown。任何想法爲什麼?我的示波器有問題嗎? https://gist.github.com/lawloretienne/7351151 – toobsco42

+0

嘿,我有完全相同的問題,GoogleAuthUtil.getToken以前工作正常,最近它開始給未知的異常。你找到了解決方案嗎? –

相關問題