Search code examples
twittertwitter4j

How to enable Enhanced URLs enrichment on Twitter API?


I'm creating an application that consumes the twitter api. I'm retrieving the tweet's and showing users.

In some cases tweets have links, as you can see in the image below.enter image description here

Reading the api documentation for twitter, I found something called "Enhanced URLs enrichment" that includes the link metadata, containing image url, title, description.

See an example of response I want to get

{
   "urls": [
      {
        "url": "https://exampleurl.com/D0n7a53c2l",
        "expanded_url": "http://exampleurl.com/18gECvy",
        "display_url": "exampleurl.com/18gECvy",
        "unwound": {
          "url": "https://www.youtube.com/watch?v=oHg5SJYRHA0",
          "status": 200,
          "title": "RickRoll'D",
          "description": "http://www.facebook.com/rickroll548 As long as trolls are still trolling, the Rick will never stop rolling."
        },
        "indices": [
          62,
          85
        ]
      }
    ]
}

Attention to the object unwound it contains exactly what I need. You can find the above response in the documentation here:

And more about Enhanced URLs enrichment here

I'm retrieving tweets by the endpoint GET statuses/user_timeline

This is my code for retrieving tweets with Twitter4j

final ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(Constant.getConsumerKeyTwitter());
cb.setOAuthConsumerSecret(Constant.getConsumerSecretTwitter());
cb.setOAuthAccessToken(tokenUser);
cb.setOAuthAccessTokenSecret(secretTokenUser);
cb.setTweetModeExtended(true);

Twitter twitter = new TwitterFactory(cb.build()).getInstance();

List<Status> statuses =  twitter.getUserTimeline(userIDToGetTweets);

Using this code, I cant receive the object unwound.

Do you know how I can enable Enhanced URLs enrichment to receive the object unwound


Solution

  • Sadly, that is only available for paying customers.

    Premium enrichments are additive metadata included in the response payload of some of the data APIs. They are available in paid subscription plans only.

    https://developer.twitter.com/en/docs/tweets/enrichments/overview

    So you'll need to get premium API subscription to get the enrichments. Sorry.