【发布时间】:2010-08-01 19:06:43
【问题描述】:
我正在寻找一种将状态更新发布到专用 Twitter 帐户的非常简单的方法。
目前我们正在使用带有 https 基本身份验证的 POST 请求到 https://api.twitter.com/1/statuses/update.xml。但 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();
【问题讨论】:
-
这与stackoverflow.com/questions/3382311/…有关,但专注于Java。