为什么我在使用状态ID转发推文时总是得到0? Twitter4j

时间:2014-10-18 17:15:48

标签: twitter twitter4j

我想转推一条推文,我知道推文ID,但我总是得到0(列表状态的大小始终为0)。我查了一下我正在搜索的推文有转推,但回报是0.有人能说出原因吗?非常感谢。这是我的代码:

public class getRetweets {

public static void main(String[] args) {

    try {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true)
              .setOAuthConsumerKey("key")
              .setOAuthConsumerSecret("keysecret")
              .setOAuthAccessToken("token")
              .setOAuthAccessTokenSecret("tokensecret");
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        List<Status> statuses = twitter.getRetweets(Long.parseLong("523516722331271169"));
        for (Status status : statuses) {
            System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText());
        }
        System.out.println("done.");
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to get retweets: " + te.getMessage());
        System.exit(-1);
    }
}

}

2 个答案:

答案 0 :(得分:0)

请执行以下操作并验证您是否有针对给定tweetID的任何转推。

        Status statusTemp = twitter.showStatus(Long.parseLong("523516722331271169"));
        System.out.println(statusTemp.getText());
        System.out.println(statusTemp.getRetweetCount());

您确定要查找正确的tweetID吗?

答案 1 :(得分:0)

带有您提供的ID的推文似乎有0转推。你的代码似乎没问题。我只是通过推文确认转推它。

public void test(){
    TwitterFactory tf = new TwitterFactory(conf);
    Twitter twitter = tf.getInstance();

    Query query = new Query("from:BBCBreaking Lynda Bellingham");
    query.setLang("en");
    QueryResult result = null;
    try {
        result = twitter.search(query);
    } catch (TwitterException e) {
        e.printStackTrace();
    }


    for(Status status : result.getTweets()){
        if(status.getRetweetCount() > 0){

            long id = status.getId();

            List<Status> statuses = null;
            try {
                statuses = twitter.getRetweets(id);
            } catch (TwitterException e) {
                e.printStackTrace();
            }

            System.out.println("Start Retweet Section------------------");
            for (Status retweet : statuses) {
                System.out.println("@" + retweet.getUser().getScreenName() + " - " + status.getText());
            }
            System.out.println("End Retweet Section------------------");

        }
    }
}

输出如下:

启动转推部分------------------

@PattenAdam - Lynda Bellingham,他在与癌症作斗争后去世了......

@brunoappr - 在与癌症作斗争后去世的Lynda Bellingham ......

@ poguesfan4ever - 在与癌症作斗争后去世的Lynda Bellingham ......

End Retweet Section ------------------

启动转推部分------------------

@holdbxcktherain - 英国女演员兼主持人Lynda Bellingham,患癌症......

@Dusty_Milo - 英国女演员兼主持人Lynda Bellingham,患有癌症......

@_ aaaamy - 英国女演员兼主持人Lynda Bellingham,患有癌症......

End Retweet Section ------------------