Java Reference
In-Depth Information
try {
// Try to open browser automatically
Desktop.getDesktop().browse(new URI(oAuthAuthorizeUrl.build()));
} catch (IOException | URISyntaxException e1) {}
Note also that protected fields and methods are used in this class, in order to extend it later (the
reason will be made clear soon).
Next, create a TwitterRESTClient class:
package com.twitter.api;
import java.io.IOException;
import java.util.Map;
import java.util.Map.Entry;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.UrlEncodedContent;
import com.google.api.client.http.javanet.NetHttpTransport;
public class TwitterRESTClient {
private static final String API_ENDPOINT_URL = " https://api.twitter.com/1.1/";
private final HttpTransport transport;
private final OAuthPostSignatureParametersProvider parametersProvider;
public TwitterRESTClient(
OAuthPostSignatureParametersProvider parametersProvider) {
this.transport = new NetHttpTransport();
this.parametersProvider = parametersProvider;
}
public String makeRequest(String operation) {
return makeRequest(operation, "GET");
}
public String makeRequest(String operation, String method) {
return makeRequest(operation, method, true, null);
}
public String makeRequest(String operation, Map<String, String> parameters) {
return makeRequest(operation, "GET", true, parameters);
}
public String makeRequest(String operation, String method,
Map<String, String> parameters) {
return makeRequest(operation, method, true, parameters);
}
public String makeRequest(String operation, String method, boolean useOAuth,
Map<String, String> parameters) {
Search WWH ::




Custom Search