Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 273
João Armando Avatar asked Nov 12 '18 14:11

João Armando


People also ask

How do I get Twitter API v2?

How can I get access to the Twitter API v2? Apps that are associated with a Project within the developer portal will have Essential access to the Twitter API v2. In order to create a project, you must have a developer account. Sign up for a developer account.

What does the Twitter API allow access to?

Our API platform provides broad access to public Twitter data that users have chosen to share with the world. We also support APIs that allow users to manage their own non-public Twitter information (e.g., Direct Messages) and provide this information to developers whom they have authorized to do so.

Is Twitter developer API free?

The Twitter API v2 includes a few access levels to help you scale your usage on the platform. In general, new accounts can quickly sign up for free, Essential access. Should you want additional access, you may choose to apply for free Elevated access and beyond.


1 Answers

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.

like image 180
Terence Eden Avatar answered Nov 09 '22 11:11

Terence Eden