2015-07-19 102 views
2

在我的代碼即時獲取谷歌+ ID令牌是這樣的:解碼GoogleAuthUtil.getToken(安卓)

Bundle bundle = new Bundle(); 
        bundle.putString(GoogleAuthUtil.KEY_REQUEST_ACTIONS, 
          "http://schemas.google.com/AddActivity http://schemas.google.com/BuyActivity"); 
        String token = GoogleAuthUtil.getToken(context, 
          Plus.AccountApi.getAccountName(mGoogleApiClient), scope,bundle); 

它返回,而我應該接受類似一個76字符序列:

{ 
    'issued_to': 'xxxxxx.apps.googleusercontent.com', 
    'user_id': 'yyyyyy', 
    'expires_in': 3457, 
    'access_type': 'online', 
    'audience': 'xxxxxx.apps.googleusercontent.com', 
    'scope': 'https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile', 
    'email': '[email protected]', 
    'verified_email': True 
} 

而且https://www.googleapis.com/oauth2/v3/tokeninfo?id_token=xyz返回此錯誤消息:

{ 
"error_description": "Invalid Value" 
} 

任何想法即將做的事情ng? 我需要解碼嗎?如果是的話如何?

回答

0

76字符的意思是它的一個Base64關鍵,這是你如何解碼爲字節數組(如回答here):

byte[] data = Base64.decode(base64, Base64.DEFAULT); 
 
String text = new String(data, "UTF-8");