I am looking for a very simple way to post status updates to a dedicated Twitter account.
Currently we are using a POST request to https://api.twitter.com/1/statuses/update.xml with https basic auth. But Twitter is going to disable this API: http://apiwiki.twitter.com/Authentication
This oauth stuff is really, really complicated and not explained well at all.
I tried to use signpost but after playing around with that for hours, all I get is a 401.
OAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret, SignatureMethod.HMAC_SHA1);
consumer.setTokenWithSecret(accessToken, tokenSecret);
URL url = new URL("https://api.twitter.com/1/statuses/update.xml");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
// Setup the header for the request
connection.setRequestMethod("POST");
connection.setRequestProperty("User-Agent", "Status Updater");
consumer.sign(connection);
// write the message
connection.setDoOutput(true);
OutputStream os = connection.getOutputStream();
os.write(("status=" + message.substring(0, Math.min(message.length(), 139))).getBytes("UTF-8"));
os.close();
// send the request
connection.getInputStream().close();
Seems like there is going to be a high demand for “simplifying” oauth for all the dedicated twitter accounts that use an external app. to post to a single account.
For a full oauth cycle using signpost’s you’ll need to make three requests the first time, after that you’ll only need to make the last request to use your access token.
Pulling some stuff from a test app. I wrote, your “quick and dirty” oauth code should look something like this…
I left the variable declarations off because I was using signpost through php (don’t ask), but all the API calls should be correct.