我已經從saved-access-token和saved-refresh-token初始化GoogleCredential變量。但我不知道檢查它是否過期?如何檢查GoogleCredential是否已過期
我知道GoogleCredential有一個函數getExpiresInSeconds。但是,如果我從saved-access-token和saved-refresh-token初始化GoogleCredential,函數getExpiresInSeconds將返回null。
這種情況getExpiresInSeconds不會空
mResponse = mFlow.newTokenRequest(code).setRedirectUri(REDIRECT_URI).execute();
mCredential = new GoogleCredential.Builder().setClientSecrets(CLIENT_ID, CLIENT_SECRET).setJsonFactory(mJsonFactory).setTransport(mHttpTransport).build();
mCredential.setFromTokenResponse(mResponse);
mCredential.getExpiresInSeconds() // will return expired value in second
但在這種情況下
String accessTokenSave = mPrefs.getString(GOOGLE_DRIVE_TOKEN, "NO KEY");
String accessRefreshTokenSave = mPrefs.getString(GOOGLE_DRIVE_REFRESH_TOKEN, "NO KEY");
mHttpTransport = new NetHttpTransport();
mJsonFactory = new JacksonFactory();
mCredential = new GoogleCredential.Builder()
.setClientSecrets(CLIENT_ID, CLIENT_SECRET)
.setJsonFactory(mJsonFactory)
.setTransport(mHttpTransport).build();
mCredential.setAccessToken(accessTokenSave);
mCredential.setRefreshToken(accessRefreshTokenSave);
mCredential.getExpiresInSeconds() // will return null value
所以,我怎麼能檢查mCredential的情況下,從accessTokenSave和accessRefreshTokenSave
我使用這個庫的真正樣本。 http://code.google.com/p/android-query/ –