0

我有处理 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);
  }
  }
4

1 回答 1

0

我换了行

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

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

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

我现在得到结果。Eclipse 显示 getTweet() 需要一个列表来存储推文的错误。

于 2013-04-09T08:01:42.870 回答