Twitter.getHomeTimeline()返回来自用户家庭时间线的最新推文列表。不幸。 Eclipse告诉我,我有一个毫无瑕疵的例外。当我查找方法时,getHomeTimeline()告诉我,当twitter网络不可用时抛出异常。怎么会这样?我是这个twitter4j API的新手,并不了解目前无法访问网络。
package com.follow3d.rob;
import java.util.List;
import twitter4j.*;
import twitter4j.conf.*;
public class Follow3d {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("XXXXXXXXXX")//removed on purpose
.setOAuthConsumerSecret("XXXXXXXXXX")//removed on purpose
.setOAuthAccessToken("XXXXXXXXXX")//removed on purpose
.setOAuthAccessTokenSecret(" XXXXXXXXXX");//removed on purpose
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
List<Status> statuses = twitter.getHomeTimeline();
for (Status status1 : statuses ){
System.out.println(status1.getUser().getName() + ": " + status1.getText());
}
}
}
抛出: TwitterException - 当Twitter服务或网络不可用时
答案 0 :(得分:0)
package com.follow3d.rob;
import java.util.List;
import twitter4j.*;
import twitter4j.conf.*;
public class Follow3d {
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey("xxxxxxxxxx")
.setOAuthConsumerSecret("xxxxxxxxxx")
.setOAuthAccessToken("xxxxxxxxxx")
.setOAuthAccessTokenSecret("xxxxxxxxxx");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
try {
List<Status> statuses = twitter.getHomeTimeline();
for (Status status1 : statuses) {
System.out.println(status1.getUser().getName() + ": " + status1.getText());
}
} catch (TwitterException name) {
System.out.println("You don't have internet connection.");
}
finally {
System.out.println("You don't have internet connection.");
}
}
}