简体   繁体   English

返回单条推文Twitter4J

[英]Return Single Tweets Twitter4J

I'm playing around with Twitter4J and i'm curious as to how i can return a single tweet (most recent tweet). 我在玩Twitter4J,我很好奇如何返回一条Tweet(最新的Tweet)。 My code is below... But it's not working. 我的代码在下面...但是它不起作用。 The documentation on the libraries website isn't great, but i've tried my best to follow it. 图书馆网站上的文档不是很好,但是我已尽力遵循它。 But any input would be great. 但是任何输入都会很棒。

It should also be noted that i'm trying to not use a loop of any description (will use loops in future projects) 还应注意,我正在尝试不使用任何描述的循环(将在以后的项目中使用循环)

Twitter twitter = TwitterFactory.getSingleton();
Query query = new Query("source:twitter4j LFC");
QueryResult result = twitter.search(query);
System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText());

I do not see any relation between result and status variables, that's the reason it is not printing anything to you. 我看不到result变量和status变量之间的任何关系,这就是它不向您输出任何内容的原因。

Try this, 尝试这个,

 Twitter twitter = TwitterFactory.getSingleton(); 
 Query query = new Query("source:twitter4j LFC"); 
 QueryResult result = twitter.search(query); 
 for (Status status : result.getTweets()) {
    System.out.println("@" + status.getUser().getScreenName() + ":" + status.getText()); 
    break; // You can delete the 'break' in future when you decide to implement/enhance the logic as you have stated
 }

reference: http://twitter4j.org/en/code-examples.html (look at #4 Search for Tweets) 参考: http : //twitter4j.org/en/code-examples.html (请参阅#4搜索推文)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM