尝试使用Processing 2.1连接到Twitter Streaming API

时间:2014-01-15 05:18:40

标签: twitter processing twitter4j

我使用processing相对较新,我目前正在尝试将我的应用程序连接到Twitter Streaming API。我已成功将Processing中的上一个项目连接到REST API

我一直在运行时收到此错误:

  

找不到名为“StatusListener”的类或类型

但是,这让我感到困惑,因为我的草图顶部有所有相关的导入。以下是 TwitterStream.pde 文件

的完整代码
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.json.*;
import twitter4j.internal.util.*;
import twitter4j.management.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import twitter4j.internal.json.*;
import java.util.*;

//Variables
TwitterConnection tc;
Twitter twitter;

//Run initially
void setup(){
  tc = new TwitterConnection();
  twitter = tc.getConnection();

  StatusListener listener = new StatusListener(){
   public void onSatus(Status status){
     System.out.println(status.getUser().getName() + " : " + status.getText());
   } 

   public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {}
   public void onTrackLimitationNotice(int numberOfLimitedStatuses) {}
   public void onException(Exception ex) {
                    ex.printStackTrace();
                }
    @Override
    public void onScrubGeo(long arg0, long arg1) {
                    // TODO Auto-generated method stub

                }
            };

     TwitterStream ts = new TwitterStreamFactory().getInstance();

}

//Run continously @ 60FPS
void draw(){


}

这是我的 TwitterConnection.pde 文件

public class TwitterConnection{

  //Variables for OAuthentication
  private String consumerKey = "xxxxxxxxxx";
  private String consumerSecret = "xxxxxxxxxxx";
  private String accessToken = "xxxxxxxx-xx";
  private String accessTokenSecret = "xxxxxxxxxxxxxxxx";

  private Twitter twitter;

  //Constructor
  public TwitterConnection(){
    configureConnection();    
  }

  public void configureConnection(){
      ConfigurationBuilder cb = new ConfigurationBuilder();
      cb.setOAuthConsumerKey(consumerKey);
      cb.setOAuthConsumerSecret(consumerSecret);
      cb.setOAuthAccessToken(accessToken);
      cb.setOAuthAccessTokenSecret(accessTokenSecret);
      TwitterFactory tf = new TwitterFactory(cb.build());
      twitter = tf.getInstance();
  }

  public Twitter getConnection(){
    return twitter;
  }  
}

我真的很感激有关此事的任何帮助。我只是无法理解我哪里出错了。非常感谢!

0 个答案:

没有答案