Search in sources :

Example 1 with CommonsHttpOAuthProvider

use of oauth.signpost.commonshttp.CommonsHttpOAuthProvider in project Brion-Learns-OAuth by brione.

the class App method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    // Only works with my code unless you create your own MyKeysProvider class
    this.setKeysProvider(new MyKeysProvider());
    mConsumer = new CommonsHttpOAuthConsumer(getKeysProvider().getKey1(), getKeysProvider().getKey2());
    mProvider = new CommonsHttpOAuthProvider(App.TWITTER_REQUEST_TOKEN_URL, App.TWITTER_ACCESS_TOKEN_URL, App.TWITTER_AUTHORIZE_URL);
    Assert.assertNotNull(mConsumer);
    Assert.assertNotNull(mProvider);
    mProvider.setOAuth10a(true);
}
Also used : CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) CommonsHttpOAuthProvider(oauth.signpost.commonshttp.CommonsHttpOAuthProvider)

Example 2 with CommonsHttpOAuthProvider

use of oauth.signpost.commonshttp.CommonsHttpOAuthProvider in project signpost-examples by mttkay.

the class FireEagleMain method main.

public static void main(String[] args) throws Exception {
    OAuthConsumer consumer = new CommonsHttpOAuthConsumer("2qnk0OzpuzzU", "Ctp1QtFbtSaFhOJbOLMCUPio9c75zIaG");
    OAuthProvider provider = new CommonsHttpOAuthProvider("https://fireeagle.yahooapis.com/oauth/request_token", "https://fireeagle.yahooapis.com/oauth/access_token", "https://fireeagle.yahoo.net/oauth/authorize");
    System.out.println("Fetching request token from Fire Eagle...");
    // we do not support callbacks, thus pass OOB
    String authUrl = provider.retrieveRequestToken(consumer, "http://www.example.com");
    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 verification code and hit ENTER when you're done");
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String code = br.readLine();
    System.out.println("Fetching access token from Fire Eagle...");
    provider.retrieveAccessToken(consumer, code);
    System.out.println("Access token: " + consumer.getToken());
    System.out.println("Token secret: " + consumer.getTokenSecret());
    HttpPost request = new HttpPost("https://fireeagle.yahooapis.com/api/0.1/update");
    StringEntity body = new StringEntity("city=hamburg&label=" + URLEncoder.encode("Send via Signpost!", "UTF-8"));
    body.setContentType("application/x-www-form-urlencoded");
    request.setEntity(body);
    consumer.sign(request);
    System.out.println("Sending update request to Fire Eagle...");
    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = httpClient.execute(request);
    System.out.println("Response: " + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) CommonsHttpOAuthProvider(oauth.signpost.commonshttp.CommonsHttpOAuthProvider) InputStreamReader(java.io.InputStreamReader) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpClient(org.apache.http.client.HttpClient) BufferedReader(java.io.BufferedReader) HttpResponse(org.apache.http.HttpResponse) CommonsHttpOAuthProvider(oauth.signpost.commonshttp.CommonsHttpOAuthProvider) OAuthProvider(oauth.signpost.OAuthProvider) OAuthConsumer(oauth.signpost.OAuthConsumer) CommonsHttpOAuthConsumer(oauth.signpost.commonshttp.CommonsHttpOAuthConsumer) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient)

Aggregations

CommonsHttpOAuthConsumer (oauth.signpost.commonshttp.CommonsHttpOAuthConsumer)2 CommonsHttpOAuthProvider (oauth.signpost.commonshttp.CommonsHttpOAuthProvider)2 BufferedReader (java.io.BufferedReader)1 InputStreamReader (java.io.InputStreamReader)1 OAuthConsumer (oauth.signpost.OAuthConsumer)1 OAuthProvider (oauth.signpost.OAuthProvider)1 HttpResponse (org.apache.http.HttpResponse)1 HttpClient (org.apache.http.client.HttpClient)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)1