我正在寻找一种非常简单的方式将状态更新发布到专用的Twitter帐户。将Twitter状态更新发布到Java专用帐户的最简单方法
目前我们正在使用POST请求https://api.twitter.com/1/statuses/update.xml与https基本身份验证。但Twitter将禁用此API:http://apiwiki.twitter.com/Authentication
这oauth的东西真的很复杂,并没有很好地解释。
我试图用路标,但与几个小时玩耍后,我得到的是一个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();
这与http://stackoverflow.com/questions/3382311/twitter-turning-off-basic-auth-is-oauth-overkill-for-some-tasks有关,但关注于Java。 – 2010-08-01 19:07:54