【发布时间】:2016-04-08 11:18:34
【问题描述】:
有时,GoogleTokenResponse.parseIdToken() 具有 NullPointerExpection,因为令牌响应不包含 ID 令牌。在不更改任何代码的情况下,有时会有 ID 令牌,有时则没有。请注意,GoogleTokenResponse.getAccessToken() 始终有效。
在不更改任何代码的情况下,即使访问令牌始终可用,ID 令牌也会从一分钟到下一分钟丢失。
我该如何调试呢?去哪里看?
我在使用 Google Play Games API 的 Android 客户端中使用此代码获取服务器身份验证代码:
PendingResult<Games.GetServerAuthCodeResult> pendingResult =
Games.getGamesServerAuthCode(mGoogleApiClient, Constants.web_client_ID);
pendingResult.setResultCallback(new ResultCallback<Games.GetServerAuthCodeResult>() {
@Override
public void onResult(Games.GetServerAuthCodeResult getTokenResult) {
sendToServer(getTokenResult.getCode());
}
});
在服务器端(Google Cloud Endpoints),我使用此代码将代码交换为令牌:
try {
tokenResponse = new GoogleAuthorizationCodeTokenRequest(
transport,mJFactory,
"https://www.googleapis.com/oauth2/v4/token",
web_client_ID,web_client_secret,
authCode,
"")
.execute();
} ...
String accessToken = tokenResponse.getAccessToken();
GoogleIdToken idToken = null;
try {
idToken = tokenResponse.parseIdToken(); //-- FAILES HERE INTERMITTENTLY!!!!
} ...
【问题讨论】:
标签: android google-cloud-endpoints google-play-games google-authentication