How to prevent automatic link preview generation for status update in Twitter API?

Viewed 659

I am using Twitter API to post status updates programmatically. However, when my status contains a link, Twitter automatically adds the preview for that link. Sometimes it's not the desired behaviour, however, I didn't find a property in the API to disable it.

I know we can remove the link preview when posting manually via the Twitter website, as described here Remove Preview Image when Posting a Link on Twitter, so I suspect that it's possible, but API never mentions it.

Also, I am using tweepy library for Python, but happy to resort to the raw POST if that solves my problem.

Any ideas what should I add to the request to prevent the link preview generation?

1 Answers

I actually tried to post to Twitter manually on the web, twice:

  1. With the generated link preview
  2. Explicitly removing the preview (clicking the cross button once the preview is generated)

While doing it, I observed the payload that the website sends to the Twitter servers (with Chrome Dev Tools).

And interestingly enough, the only difference between these two tweets was only one property: card_uri: tombstone://card. More specifically, this property was present in the tweet without the preview.

After that, I actually tried to go and add card_uri property to my status update request, and it actually did the job: the preview was not automatically rendered.

Conviniently, tweepy library has an optional card_uri argument in the update_status menthod.

To sum up, you need to set card_uri='tombstone://card' in your request to prevent Twitter from autogenerating the link previews.

Unfortunately, I didn't find any references to this in the API (or in Google at all), so I am not confident that this is a long-lasting solution, but that's at least something to start with.

Related