我需要设置一个例程来在使用eBay sdk时检查令牌。从我所看到的,我需要使用GetClientAlertsAuthTokenCall并执行它。我不确定我是如何执行它的。或者有更好的方法来检查即将到期的令牌吗?这是我到目前为止检查的内容。
public boolean isTokenExpiring() {
try {
GetClientAlertsAuthTokenCall tokenCall = new GetClientAlertsAuthTokenCall(getApiContext());
tokenCall.execute(null);
Calendar expireCalendar=tokenCall.getReturnedHardExpirationTime();
Calendar currentCalendar=Calendar.getInstance();
} catch (Exception e) {
return false;
}
return false;
}
答案 0 :(得分:0)
找到答案。这是我使用的代码。请注意,我保存了令牌,所以我用不同的方法来获取它。
public boolean isTokenExpiring() {
try {
ApiContext apiContext = new ApiContext();
//set Api Token to access eBay Api Server
ApiCredential cred = apiContext.getApiCredential();
ApiAccount account = new ApiAccount();
account.setApplication(APP_ID);
account.setCertificate(CERT_ID);
account.setDeveloper(DEV_ID);
cred.setApiAccount(account);
cred.seteBayToken(getLogInToken());
apiContext.setApiServerUrl(SOAP_URL);
apiContext.setApiCredential(cred);
GetTokenStatusCall call = new GetTokenStatusCall(apiContext);
TokenStatusType status = call.getTokenStatus();
Calendar expCalendar = status.getExpirationTime();
Calendar cur = Calendar.getInstance();
cur.add(Calendar.DATE, -7);
if (expCalendar.getTimeInMillis() < cur.getTimeInMillis()) {
return true;
}
return false;
} catch (Exception e) {
System.out.println(e.getMessage());
}
return true;
}