Search code examples
javatwittertwitter4j

Twitter4j: User's profile URL is always null


I am trying to retrieve User's profile having a valid token. I am able to get the profile with all the info, but with no profile URL Tried both

 User user = twitter.users().showUser(twitter.getId());

and

 User user = twitter.verifyCredentials();

Both requests work fine but return null when I call

user.getURL()

What can be a problem? Profile URL seems to be public information, I don't think am supposed to set any specific parameters or obtain permissions, provided I already have the token. My Twitter4J version is 4.0.6


Solution

  • I think user.getURL() does not return what you think.

    According to documentation user.getURL() returns the URL that users provide in their profile. Not the URL of the user account.

    You can check this documentation's URL section for more info: https://developer.twitter.com/en/docs/twitter-api/v1/data-dictionary/object-model/user

    If you need to generate an URL for the user profile you can try something like this:

    User user = twitter.users().showUser(twitter.getId());
    String profileURL = "https://twitter.com/" + user.getScreenName()