0
我在練上創建在以下鏈接找到的Twitter圖形客戶端的NetBeans教程:http://netbeans.org/kb/docs/websvc/twitter-swing.html我使用NetBeans 7.1NetBeans教程:創建圖形客戶端Twitter並
下面是教程的代碼片段
public class TwitterFrame extends javax.swing.JFrame {
/**
* Creates new form TwitterFrame
*/
public TwitterFrame() {
initComponents();
try {
initUserInfo();
} catch (IOException ex) {
Logger.getLogger(TwitterFrame.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void initUserInfo() throws MalformedURLException, IOException {
//Create an instance of the internal service class
client = new Twitter_OAuth_user_timeline__format_JerseyClient("xml");
//Log in, get tokens, and append the tokens to the consumer and secret
//keys
client.login();
client.initOAuth();
//Call getUserTimeline, get a list of statuses, pass the most recent
//status as a StatusType object, and display the text of that object
//in the JTextField
Statuses statuses = client.getUserTimeline(Statuses.class, null, null, null, "1");
twitter.twitteroauth.twitterresponse.StatusType st = statuses.getStatus().get(0);
jTextField1.setText(st.getText().trim());
//Get a UserType object from the StatusType object, get the URL of that
//user's icon, and display that icon in the JLabel
UserType user = st.getUser();
String iconSrc = user.getProfileImageUrl();
URL iconUrl = new URL(iconSrc);
ImageIcon icon = new ImageIcon(iconUrl, user.getScreenName());
jLabel1.setIcon(icon);
}
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TwitterFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TwitterFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TwitterFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TwitterFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TwitterFrame().setVisible(true);
}
});
}
但螞蟻時間我在netbeans上運行代碼我得到以下錯誤。
run:
Exception in thread "AWT-EventQueue-0" com.sun.jersey.api.client.UniformInterfaceException: GET http://twitter.com/oauth/request_token returned a response status of 301 Moved Permanently
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:676)
at com.sun.jersey.api.client.WebResource.get(WebResource.java:191)
at twitterclient.TwitterFrame$Twitter_OAuth_user_timeline__format_JerseyClient.getOAuthRequestToken(TwitterFrame.java:268)
at twitterclient.TwitterFrame$Twitter_OAuth_user_timeline__format_JerseyClient.login(TwitterFrame.java:255)
at twitterclient.TwitterFrame.initUserInfo(TwitterFrame.java:123)
at twitterclient.TwitterFrame.<init>(TwitterFrame.java:37)
at twitterclient.TwitterFrame$2.run(TwitterFrame.java:177)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
任何人有關於如何運行教程的建議。 謝謝。
謝謝你會試圖找回你 – 2013-02-14 14:35:31