2017-01-24 4 views
1

twitter4jでツイートを取得しようとしています。私はサンプルコードを試して、それが動作しない理由を見る - 私はStatusListenerを変換することはできません。しかし私は私の問題を解決することはできません。Twitter4j:StatusListenerをtwitter4j.StreamListenerに変換できません

誰かがこれを解決する方法を知っていますか?

import twitter4j.*; 
import twitter4j.conf.ConfigurationBuilder; 

import java.io.IOException; 

public class Home 
{ 
    public static void main (String args[]) throws TwitterException, IOException 
    { 
     ConfigurationBuilder cf = new ConfigurationBuilder(); 
     cf.setDebugEnabled(true) 
       .setOAuthConsumerKey("") 
       .setOAuthConsumerSecret("") 
       .setOAuthAccessToken("") 
       .setOAuthAccessTokenSecret(""); 

     StatusListener listener = new StatusListener(){ 
      public void onStatus(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(); 
      } 
     }; 
     TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); 
     twitterStream.addListener(listener); 
     twitterStream.sample(); 
    } 
} 

答えて

0

あなたはこれは次のようになりますStatusListener

を実装するあなたの匿名クラスに2つのメソッドの実装を逃している:

StatusListener listener = new StatusListener() { 

    public void onStatus(Status status) { 
     System.out.println(status.getUser().getName() + " : " + status.getText()); 
    } 

    public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {} 
    public void onTrackLimitationNotice(int numberOfLimitedStatuses) {} 

    @Override 
    public void onScrubGeo(long l, long l1) {} 

    @Override 
    public void onStallWarning(StallWarning stallWarning) {} 

    public void onException(Exception ex) { 
     ex.printStackTrace(); 
    } 
}; 
+0

おかげで、それはそれでした! –

関連する問題