Search in sources :

Example 6 with DefaultOAuthProvider

use of oauth.signpost.basic.DefaultOAuthProvider 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

DefaultOAuthProvider (oauth.signpost.basic.DefaultOAuthProvider)6 OAuthConsumer (oauth.signpost.OAuthConsumer)5 OAuthProvider (oauth.signpost.OAuthProvider)5 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)3 HttpURLConnection (java.net.HttpURLConnection)3 URL (java.net.URL)3 DefaultOAuthConsumer (oauth.signpost.basic.DefaultOAuthConsumer)3 IOException (java.io.IOException)1 OAuthCommunicationException (oauth.signpost.exception.OAuthCommunicationException)1 OAuthException (oauth.signpost.exception.OAuthException)1 OAuthExpectationFailedException (oauth.signpost.exception.OAuthExpectationFailedException)1 OAuthMessageSignerException (oauth.signpost.exception.OAuthMessageSignerException)1 OAuthNotAuthorizedException (oauth.signpost.exception.OAuthNotAuthorizedException)1 GoogleOAuthConsumer (org.dataportabilityproject.shared.signpost.GoogleOAuthConsumer)1