This tutorial was originally posted to the Twitter Developer Blog
A surprisingly-common question I hear from developers, bloggers and researchers using Twitter is, "how can I get the original URL for a Tweet"?
You've probably seen those long numbers in the URLs in your web browser when you click into a Tweet's detail page. Those are
Tweet IDs. Every one of them is unique. When Twitter started out, the system was sufficiently small that it was easy enough to just have a low, incrementing number. Fun fact!
@jack's very first Tweet has
jack⚡️just setting up my twttr20:50 PM - 21 Mar 2006
Over time, and as the platform scaled to require multiple and parallel backend services, a system that consistently generated unique IDs across servers and datastores was needed - so, Twitter developed Snowflake, which is a service and method for doing just that.1
That's how we end up with those long ID numbers - but what if you only have a Tweet ID, and you want to see the original Tweet on the website? You don't know which Twitter user originally Tweeted it, so you don't have the username, and can't make a URL from it easily...
Well, if the Tweet is available (that means, it has not been deleted and is not a protected Tweet belonging to an account you do not follow), there's a trick that you can use here.
Let's pick a recent Tweet with ID
1234903157580296192, for example.
The long way to do this would be to use the official Twitter API, and pull back the Tweet object and associated user information. Then, we'd pick out the screen name of the user that posted the Tweet from the JSON response, and do something like this, in pseudo-code:
URL = "https://twitter.com/[screen name]/status/[Tweet ID]"
"... oh! But I don't have a Twitter Developer Account / I don't want to build an app just to do this simple thing"
No problem! There's a handy trick, and you can even use it to generate embedded Tweets via markup from publish.twitter.com (or, if you do have an app, you can also grab the HTML markup
using magic directly from the oEmbed API endpoint, without ever having to know the user's original screen name)
Here's the secret...
Each Tweet ID is already unique, so you don't need to know the user that posted it! It turns out, you can add any username to the URL, and Twitter will work it out for you. I always like to use
So now, with our previous example:
URL = "https://twitter.com/twitter/status/1234903157580296192"
Tony VuLooking for a remote developer job? I put together this tutorial on how you can build an app that searches for remote developer job listings!
It uses the Twitter Labs API, React, & NodeJS.
Check it out 👇
#twitterapi #remotejob @TwitterDev @TwitterAPI
bit.ly/32QJ59k18:07 PM - 03 Mar 2020
I've also answered a few questions about this over on Stack Overflow, in case you want to dig a bit deeper into alternative examples.