我在发布到Twitter时遇到问题,只发布到我的帐户 以下是我如何实现它:
在课堂上声明:private ConfigurationBuilder configurationBuilder;
在表单打开方法时放置它:
configurationBuilder = new ConfigurationBuilder();
configurationBuilder.setDebugEnabled(true)
.setOAuthConsumerKey("*****")
.setOAuthConsumerSecret("*****")
.setOAuthAccessToken("******")
.setOAuthAccessTokenSecret("*****");
放置在动作监听器上的按钮:
try {
if (jTextPane.getSelectedText().length() <= 127) {
TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
Twitter twitter = twitterFactory.getInstance();
Status status = twitter.updateStatus("#polytechnic " + jTextPane.getSelectedText());
JOptionPane.showMessageDialog(null, "Tweet Posted Successfully.");
} else {
JOptionPane.showMessageDialog(null, "You can tweet 127 character only.");
}
} catch (TwitterException ex) {
Logger.getLogger(PolyNote.class.getName()).log(Level.SEVERE, null, ex);
}
从我的研究中我知道问题在于使用访问令牌密钥,但是如果没有它就无法找到配置它!