![](/img/trans.png)
[英]Why is twitter4j TwitterStream not filtering user's tweets?
[英]Is it normal that sampling tweets using TwitterStream as in Twitter4J code example, I get just mainly question marks as user name and status?
我使用了Twitter4j中“代碼示例”部分中的代碼:
public static void main(String[] args) throws TwitterException, IOException{
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);
// sample() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously.
twitterStream.sample();
}
如您所見,在上面的代碼中,在“ onStatus”方法內部有一個println。 下圖顯示了我主要從該代碼中獲得的信息。 正常嗎
的確,我只過濾用戶名中沒有問號的狀態,我幾乎什么也沒有。 此外,我還應該過濾公開位置的用戶。 關於這一點,我也想問一下兩者之間有什么區別?
user.isGeoEnabled()
和
user.getLocation() != ""
您將獲得的響應是UTF-8編碼的https://dev.twitter.com/tags/utf-8
如果您查看輸出中的某些帳戶,它們將包含非西歐字符https://twitter.com/tomokichi_koyo 。 這些正在破壞輸出。
嘗試改為寫入文件,然后使用支持UTF-8的編輯器打開。 關於將Java和操作系統設置為默認為UTF-8的方法有多種答案,但是您需要查找特定的組合https://stackoverflow.com/search?q=windows+console+java+utf-8
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.