使用以下代码和twitter4j库管理最终将我自己的推文发送到处理。我现在一直在努力调整代码来吸引特定用户的推文,没有任何运气,无论网上有多少人发布了“工作代码”。有人可以指导我,并告诉我究竟需要改变什么?谢谢!
import twitter4j.util.*;
import twitter4j.*;
import twitter4j.management.*;
import twitter4j.api.*;
import twitter4j.conf.*;
import twitter4j.json.*;
import twitter4j.auth.*;
import java.util.*;
List<Status>statuses = null;
TwitterFactory twitterFactory;
Twitter twitter;
void setup() {
size(100, 100);
background(0);
connectTwitter();
getTimeline();
}
void draw() {
background(0);
}
// Initial connection
void connectTwitter() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("XXXX");
cb.setOAuthConsumerSecret("XXXX");
cb.setOAuthAccessToken("XXXX");
cb.setOAuthAccessTokenSecret("XXXX");
twitterFactory = new TwitterFactory(cb.build());
twitter = twitterFactory.getInstance();
println("connected");
}
// Get your tweets
void getTimeline() {
try {
statuses = twitter.getUserTimeline();
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status:statuses) {
println(status.getUser().getName() + ": " + status.getText());
}
}
编辑 - 用于获取用户推文的修订代码。不产生任何错误或结果......
void getUserTimeLine(long stephenfry) {
try {
ResponseList<Status> statuses = twitter.getUserTimeline(stephenfry);
}
catch(TwitterException e) {
println("Get timeline: " + e + " Status code: " + e.getStatusCode());
}
for (Status status : statuses) {
System.out.println(status.getText());
}
}
答案 0 :(得分:0)
您只需在代码中添加以下内容即可检索任何用户时间表 -
void getUserTimeLine(long userID/*You can also use screenName*/) {
ResponseList<Status> statuses = twitter.getUserTimeline(userID/*You can also use screenName*/);
for (Status status : statuses) {
System.out.println(status.getText());
}
}