我已经从 save-access-token 和 saved-refresh-token 初始化了 GoogleCredential 变量。但我不知道检查它是否过期?
我知道 GoogleCredential 有一个函数 getExpiresInSeconds。但是,如果我从保存的访问令牌和保存的刷新令牌初始化 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 加载它