use of com.uwetrottmann.trakt.v2.TraktHttpClient in project aos-MediaLib by nova-video-player.
the class Trakt method refreshAccessToken.
private boolean refreshAccessToken() {
Log.d(TAG, "refreshAccessToken()");
try {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(mContext);
String refreshToken = getRefreshTokenFromPreferences(pref);
if (refreshToken == null || refreshToken.isEmpty()) {
Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
mContext.sendBroadcast(intent);
} else {
OAuthClientRequest request = TraktV2.getAccessTokenRefreshRequest(API_KEY, API_SECRET, "http://localhost", refreshToken);
OAuthClient client = new OAuthClient(new TraktHttpClient());
OAuthJSONAccessTokenResponse res = client.accessToken(request);
if (res != null && res.getAccessToken() != null && !res.getAccessToken().isEmpty()) {
setAccessToken(pref, res.getAccessToken());
mTraktV2.setAccessToken(res.getAccessToken());
setRefreshToken(pref, res.getRefreshToken());
return true;
}
}
} catch (OAuthSystemException e) {
Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
mContext.sendBroadcast(intent);
} catch (OAuthProblemException e) {
Intent intent = new Intent(TRAKT_ISSUE_REFRESH_TOKEN);
intent.setPackage(ArchosUtils.getGlobalContext().getPackageName());
mContext.sendBroadcast(intent);
}
return false;
}
Aggregations