use of oauth.signpost.basic.DefaultOAuthConsumer in project signpost-examples by mttkay.
the class TwitterMain method main.
public static void main(String[] args) throws Exception {
OAuthConsumer consumer = new DefaultOAuthConsumer("iIlNngv1KdV6XzNYkoLA", "exQ94pBpLXFcyttvLoxU2nrktThrlsj580zjYzmoM", SignatureMethod.HMAC_SHA1);
OAuthProvider provider = new DefaultOAuthProvider("https://api.twitter.com/oauth/request_token", "https://api.twitter.com/oauth/access_token", "https://api.twitter.com/oauth/authorize");
System.out.println("Fetching request token from Twitter...");
// we do not support callbacks, thus pass OOB
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
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://twitter.com/statuses/mentions.xml");
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
System.out.println("Sending request to Twitter...");
request.connect();
System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
}
use of oauth.signpost.basic.DefaultOAuthConsumer in project openhab1-addons by openhab.
the class WithingsAccount method createConsumer.
public OAuthConsumer createConsumer() {
consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
consumer.setSigningStrategy(new AuthorizationHeaderSigningStrategy());
consumer.setMessageSigner(new HmacSha1MessageSigner());
return consumer;
}
use of oauth.signpost.basic.DefaultOAuthConsumer in project androidquery by androidquery.
the class TwitterHandle method applyToken.
@Override
public void applyToken(AbstractAjaxCallback<?, ?> cb, HttpURLConnection conn) {
AQUtility.debug("apply token multipart", cb.getUrl());
OAuthConsumer oac = new DefaultOAuthConsumer(consumer.getConsumerKey(), consumer.getConsumerSecret());
oac.setTokenWithSecret(consumer.getToken(), consumer.getTokenSecret());
try {
oac.sign(conn);
} catch (Exception e) {
AQUtility.report(e);
}
}
use of oauth.signpost.basic.DefaultOAuthConsumer in project serverless by bluenimble.
the class OAuthHttpRequestVisitor method visit.
@Override
public void visit(HttpRequest request, HttpURLConnection connection) throws HttpRequestWriteException {
HttpEndpoint endpoint = ((AbstractHttpRequest) request).getEndpoint();
OAuthConsumer consumer = new DefaultOAuthConsumer(key, secret);
HttpParameters encodedParams = new HttpParameters();
List<HttpParameter> params = request.getParameters();
if (params != null && !params.isEmpty()) {
for (HttpParameter p : params) {
if (p.getValue() != null) {
encodedParams.put(p.getName(), OAuth.percentEncode(String.valueOf(p.getValue())));
}
}
}
encodedParams.put("realm", endpoint.getScheme() + "://" + endpoint.getHost() + endpoint.getPath());
consumer.setAdditionalParameters(encodedParams);
try {
consumer.sign(connection);
} catch (Exception e) {
throw new HttpRequestWriteException(e.getMessage(), e);
}
}
use of oauth.signpost.basic.DefaultOAuthConsumer in project signpost-examples by mttkay.
the class GoogleMain method main.
public static void main(String[] args) throws Exception {
OAuthConsumer consumer = new DefaultOAuthConsumer("matthiaskaeppler.de", "etpfOSfQ4e9xnfgOJETy4D56");
String scope = "http://www.blogger.com/feeds";
OAuthProvider provider = new DefaultOAuthProvider("https://www.google.com/accounts/OAuthGetRequestToken?scope=" + URLEncoder.encode(scope, "utf-8"), "https://www.google.com/accounts/OAuthGetAccessToken", "https://www.google.com/accounts/OAuthAuthorizeToken?hd=default");
System.out.println("Fetching request token...");
String authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
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 verificationCode = br.readLine();
System.out.println("Fetching access token...");
provider.retrieveAccessToken(consumer, verificationCode.trim());
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
URL url = new URL("http://www.blogger.com/feeds/default/blogs");
HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
System.out.println("Sending request...");
request.connect();
System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
}
Aggregations