1
나는라이브러리를 사용하여 트위터 스트림에서 무작위 샘플을 얻고 트윗의 사용자 이름과 텍스트를 인쇄하려고합니다.트위터 스트림에서 샘플을 얻고 화면에 출력하는 방법
OAuth
까지 정확한 용어를 이해할 수 있는지 확실하지 않습니다. 이것은 내 계정을 위해 필요한 것입니까, 아니면 다른 개인 계정에 액세스하는 경우입니까?
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
Syntax error on token(s), misplaced construct(s)
Syntax error on token "setDebugEnabled", = expected after this token
at tweet1.ConfigurationBuilder.<init>(ConfigurationBuilder.java:9)
at tweet1.Twit4jEx1.main(Twit4jEx1.java:21)
어떤 제안 : 나는 다음과 같은 얻을 Twit4jEx1
실행하면
package tweet1;
import java.io.IOException;
import twitter4j.Status;
import twitter4j.StatusDeletionNotice;
import twitter4j.StatusListener;
import twitter4j.TwitterException;
import twitter4j.TwitterStream;
import twitter4j.TwitterStreamFactory;
import twitter4j.auth.BasicAuthorization;
public class Twit4jEx1 {
/**
* @param args
*/
// TODO Auto-generated method stub
public static void main(String[] args) throws TwitterException, IOException{
// BasicAuthorization ba1 = new BasicAuthorization("userName", "pword");
ConfigurationBuilder cb = new ConfigurationBuilder();
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();
}
@Override
public void onScrubGeo(long arg0, long arg1) {
// TODO Auto-generated method stub
}
};
TwitterStream twitterStream = new TwitterStreamFactory().getInstance();
// sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
twitterStream.sample();
}
}
ConfigurationBuilder 클래스
package tweet1;
import twitter4j.Twitter;
import twitter4j.TwitterFactory;
//import twitter4j.conf.ConfigurationBuilder;
public class ConfigurationBuilder {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("***")
.setOAuthConsumerSecret("***")
.setOAuthAccessToken("***")
.setOAuthAccessTokenSecret("***");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
}
:
여기 내 코드입니까?
당신은 이것을 보았습니까 -> http://twitter4j.org/en/code-examples.html – AnujKu
그리고 이것 -> http://stackoverflow.com/questions/7547470/twitter4j-twitterstream-doesnt-get- all-tweets 외에도 이것을 제외하고 -> http://twitter4j.org/en/javadoc/index.html – AnujKu
@AnujKulkarni : 예, 코드를 가져 왔습니다. – screechOwl