Hen*_*ann 1 java twitter oauth
我正在寻找一种将状态更新发布到专用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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3864 次 |
| 最近记录: |