Search code examples
javatwitter4j

Extract tweet from URL using Java?


According to the things I've found twitter4J seems to be the most prominent tool when it comes to Java and Twitter. I went through the code examples and javadoc but I couldn't find a way to do this.

What I want to do is, extract the tweet (content of the tweet) using the URL of it. I tried using JSOUP and the CSS selector but when its a conversation it pulls all the tweets of it. How can I do it using Twitter4J?

Input tweet URL -> Output the content of the tweet


Solution

  • Using jsoup is easier, u can do this:

     Document doc = Jsoup.connect("the tweet url here").timeout(10*1000).get();
     Element tweet = doc.select(".js-tweet-text-container").first();
    

    now u can use the tweet object to parse the information.