Twitter4j: how to get twit url from status?

java, twitter

Solution

The `getURLEntities()` method returns any URLs in the content of the tweet itself, not the URL of the tweet.

Fortunately the URL of a tweet is in the following format:

`https://twitter.com/[screen name of user]/status/[id of status]`

So you can get the URL of a status with this code:

Status status;
String url= "https://twitter.com/" + status.getUser().getScreenName() 
    + "/status/" + status.getId();
System.out.println(url);

Problem

I am using twitter4j-3.0.5 on Windows. When new status arrives to the StatusListener.onStatus() method, I would like to print out it's URL but I don't find any appropriate method. status.getURLEntities() is always empty, even tough if I look at the json passed to the client, the url field is not empty and contains valid URL. I just don't know how to get this value from java. Please advise.

Original source