Search in sources :

Example 6 with DefaultOAuthConsumer

use of oauth.signpost.basic.DefaultOAuthConsumer in project signpost-examples by mttkay.

the class NetflixMain method main.

public static void main(String[] args) throws Exception {
    OAuthConsumer consumer = new DefaultOAuthConsumer(CONSUMER_KEY, CONSUMER_SECRET);
    OAuthProvider provider = new DefaultOAuthProvider(NETFLIX_REQUEST_TOKEN_URL, NETFLIX_ACCESS_TOKEN_URL, NETFLIX_AUTHORIZE_URL);
    System.out.println("Fetching request token from Netflix...");
    // we do not support callbacks, thus pass OOB
    String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
    authUrl = OAuth.addQueryParameters(authUrl, OAuth.OAUTH_CONSUMER_KEY, CONSUMER_KEY, "application_name", APPLICATION_NAME);
    System.out.println("Request token: " + consumer.getToken());
    System.out.println("Token secret: " + consumer.getTokenSecret());
    System.out.println("Now visit:\n" + authUrl + "\n... and grant this app authorization");
    System.out.println("Enter the PIN code and hit ENTER when you're done:");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String pin = br.readLine();
    System.out.println("Fetching access token from Twitter...");
    provider.retrieveAccessToken(consumer, pin);
    System.out.println("Access token: " + consumer.getToken());
    System.out.println("Token secret: " + consumer.getTokenSecret());
    URL url = new URL("http://api.netflix.com/catalog/titles");
    HttpURLConnection request = (HttpURLConnection) url.openConnection();
    consumer.sign(request);
    System.out.println("Sending request...");
    request.connect();
    System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
}
Also used : HttpURLConnection(java.net.HttpURLConnection) InputStreamReader(java.io.InputStreamReader) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) BufferedReader(java.io.BufferedReader) DefaultOAuthProvider(oauth.signpost.basic.DefaultOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) DefaultOAuthConsumer(oauth.signpost.basic.DefaultOAuthConsumer) OAuthConsumer(oauth.signpost.OAuthConsumer) URL(java.net.URL)

Aggregations

DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)6 OAuthConsumer (oauth.signpost.OAuthConsumer)5 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 OAuthProvider (oauth.signpost.OAuthProvider)3 DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)3 HttpEndpoint (com.bluenimble.platform.http.HttpEndpoint)1 HttpParameter (com.bluenimble.platform.http.HttpParameter)1 HttpRequestWriteException (com.bluenimble.platform.http.request.HttpRequestWriteException)1 AbstractHttpRequest (com.bluenimble.platform.http.request.impls.AbstractHttpRequest)1 CommonsHttpOAuthConsumer (oauth.signpost.commonshttp.CommonsHttpOAuthConsumer)1 HttpParameters (oauth.signpost.http.HttpParameters)1 AuthorizationHeaderSigningStrategy (oauth.signpost.signature.AuthorizationHeaderSigningStrategy)1 HmacSha1MessageSigner (oauth.signpost.signature.HmacSha1MessageSigner)1