2015-07-19 99 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");