Java Reference
In-Depth Information
boolean requiresVerification) {
this.configurationName = configurationName;
this.consumerKey = consumerKey;
this.consumerSecret = consumerSecret;
this.requestTokenUrl = requestTokenUrl;
this.authorizeUrl = authorizeUrl;
this.accessTokenUrl = accessTokenUrl;
this.requiresVerification = requiresVerification;
this.transport = new NetHttpTransport();
this.signer = new OAuthHmacSigner();
this.signer.clientSharedSecret = consumerSecret;
}
public OAuthParameters getOAuthParameters() {
OAuthParameters parameters = new OAuthParameters();
parameters.consumerKey = consumerKey;
OAuthCredentialsResponse accessToken = getAccessToken();
parameters.token = accessToken.token;
// Construct a new signer
OAuthHmacSigner requestSigner = new OAuthHmacSigner();
requestSigner.clientSharedSecret = consumerSecret;
requestSigner.tokenSharedSecret = accessToken.tokenSecret;
parameters.signer = requestSigner;
return parameters;
}
public OAuthCredentialsResponse getAccessToken() {
return getAccessToken(false);
}
public OAuthCredentialsResponse getAccessToken(boolean forceNewToken) {
OAuthCredentialsResponse token = getStoredAccessToken();
if (!forceNewToken && token != null)
return token;
OAuthCredentialsResponse requestToken = getRequestToken();
OAuthCredentialsResponse accessToken = getAccessToken(requestToken);
return accessToken;
}
protected OAuthCredentialsResponse getStoredAccessToken() {
String path = "tokens/"+configurationName+".txt";
if (Files.notExists(Paths.get(path)))
return null;
try {
List<String> lines = Files.readAllLines(Paths.get(path),
StandardCharsets.UTF_8);
OAuthCredentialsResponse accessToken = new OAuthCredentialsResponse();
accessToken.token = lines.get(0);
Search WWH ::




Custom Search