处理和Twitter4j,搜索推文的问题

时间:2013-04-08 14:18:17

标签: processing twitter4j

我有处理2.0和twitter4j 3.0.3;当我尝试运行该程序时,我收到错误消息 “函数”getTweet()不存在“。

我试过getStatuses而无济于事,我得到的错误信息是该函数不存在。

帮助?

ArrayList<String> words = new ArrayList();
TwitterFactory twitterFactory;
Twitter twitter;

void setup() {

  size(500, 500);
  background(0);
  smooth();
  connectTwitter();
}

 void draw() {
   //draw fade rectangle
   fill(0, 1);
   rect(0, 0, width, height);

   //draw arraylist words
   int i = (frameCount % words.size());
   String word = words.get(i);

   fill(255, random(50, 150));
   textSize(random(10, 30));
   text(word, random(width), random(height));
 }

// Initial connection
void connectTwitter() {

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("FvnrJfRMsMUCEhL0xxPegQ");
cb.setOAuthConsumerSecret("ZSnKgo6EQmq9wVd5gCMbufcMP5ztFuQhVwKpJvDhAY");
cb.setOAuthAccessToken("274686457-ZiYxpWchtcwHod7UXPjLCj18djl9CyNrk1HMqtQx");
cb.setOAuthAccessTokenSecret("kafd2QHznAu4Mu0R9x5HNyeyA4J3UwCOpETQYeDU");

  twitterFactory = new TwitterFactory(cb.build());
  twitter = twitterFactory.getInstance();
  Query query = new Query("#BioshockInfinite");
  query.setCount(100);

  try {
    QueryResult result = twitter.search(query);
    ArrayList Status = (ArrayList) result.getTweet();

    for (int i = 0; i < tweet.size(); i++) {
      Status s = (Status) tweet.get(i);
      User user = s.getUser;
      String name = user.getName();
      String msg = s.getText();
      Date d = s.getCreatedAt();
      println("Tweet by" + user + "at" + d + ":" + msg);
     }  
  }
  catch (TwitterException te) {
    println("Couldn't connect:" + te);
  }
  }

1 个答案:

答案 0 :(得分:0)

我改变了行

ArrayList Status = (ArrayList) result.getTweet();

(无论如何看起来有点奇怪)

List<Status> tweets = result.getTweets();

我现在得到了结果。 Eclipse显示错误,getTweet()希望List存储推文。