public void getTokenCredentials(LocalUserDetail user) throws FitbitAPIException {
// Get cached resource credentials:
APIResourceCredentials resourceCredentials = getResourceCredentialsByUser(user);
if (resourceCredentials == null) {
throw new FitbitAPIException("User " + user.getUserId() + " does not have resource credentials. Need to grant authorization first.");
}
String tempToken = resourceCredentials.getTempToken();
String tempTokenSecret = resourceCredentials.getTempTokenSecret();
if (tempToken == null || tempTokenSecret == null) {
throw new FitbitAPIException("Resource credentials for resource " + user.getUserId() + " are in an invalid state: temporary token or secret is null.");
}
// Get and save token credentials:
AccessToken accessToken = client.getOAuthAccessToken(tempToken, tempTokenSecret, resourceCredentials.getTempTokenVerifier());
resourceCredentials.setAccessToken(accessToken.getToken());