twitter4j - get tweets by ID

后端 未结 2 2039
隐瞒了意图╮
隐瞒了意图╮ 2021-02-10 18:54

How can I get the tweets when I have the tweet ID and the user ID ? I have a file containing lines like :

userID  tweetID

I guess I should go b

2条回答
  •  北海茫月
    2021-02-10 19:06

    Well it was no search call. The tweet apparently is called Status and the code to retrieve one by ID is :

        final Twitter twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
        AccessToken accessToken = new AccessToken(TWITTER_TOKEN,
                TWITTER_TOKEN_SECRET);
        twitter.setOAuthAccessToken(accessToken);
        try {
            Status status = twitter.showStatus(Long.parseLong(tweetID));
            if (status == null) { // 
                // don't know if needed - T4J docs are very bad
            } else {
                System.out.println("@" + status.getUser().getScreenName()
                            + " - " + status.getText());
            }
        } catch (TwitterException e) {
            System.err.print("Failed to search tweets: " + e.getMessage());
            // e.printStackTrace();
            // DON'T KNOW IF THIS IS THROWN WHEN ID IS INVALID
        }
    

提交回复
热议问题