gpt4 book ai didi

java - Netbeans 教程 : Creating a graphical client for twitter

转载 作者:行者123 更新时间:2023-12-02 07:16:35 27 4
gpt4 key购买 nike

我正在练习有关为 twitter 创建图形客户端的 netbeans 教程,可在以下链接中找到:http://netbeans.org/kb/docs/websvc/twitter-swing.html我正在使用 Netbeans 7.1

下面是教程的代码片段

    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)

任何对如何运行教程有建议的人。谢谢。

最佳答案

我想自 Netbeans 教程编写以来 URL 已经发生了变化,现在根据 Twitter documentationhttps://api.twitter.com/oauth/request_token .

异常表明您调用:http://twitter.com/oauth/request_token

您错过了 api。

关于java - Netbeans 教程 : Creating a graphical client for twitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14874038/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com