93

I have some Javascript that uses Twitter API to get tweets. I parse the data and use jQuery to generate HTML for the DOM.

An aspect of what I want to display is a "View this tweet" link -- yeah, sorta sounds silly, but it allows a user to get a URL for a specific tweet.

I am generating an a tag with an href. The URL is of the form:

http://twitter.com/{twitter-user-id}/status/{tweet-status-id}

where the content in curly braces is actual data extracted from the tweet (no, I am not including the curly braces). For example:

http://twitter.com/Atechtrader/status/57432099984130050

What happens in operation is that this works for some tweets, but not others. For the ones that fails, the Twitter server responds with content that says the requested page does not exist.

Am I doing something wrong?

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
Zhami
  • 19,033
  • 14
  • 48
  • 47
  • 1
    Yes, I was doing something wrong -- I wasn't extracting the string ID. My bad. Sorry for the noise. – Zhami Apr 13 '11 at 16:08

6 Answers6

157

https://twitter.com/statuses/ID should work.
it will redirect to the needed status.

Sagiv Ofek
  • 25,190
  • 8
  • 60
  • 55
  • 31
    This does not work on mobile devices, use the longer form if you want a link that can be open from mobile: http://twitter.com/twitter-user-screen-name/status/tweet-id-str – UKatz May 03 '15 at 20:14
  • 2
    @UKatz unfortunately that link seems broken :( – clapas Nov 29 '17 at 14:34
  • 1
    @clapas I think that’s just an example URL, you would substitute `twitter-user-screen-name` and `tweet-id-str` with the appropriate values for a working link. – Thomas Foster Feb 21 '18 at 23:19
  • This works on computer browser. However, if you are using a mobile device, Twitter server will automatically redirect it to `https://mobile.twitter.com/statuses/ID` , which leads to an error page. So the over all solution is still `https://twitter.com/{twitter-user-id}/status/{tweet-status-id}`. – Owen Zhao Apr 26 '19 at 02:34
  • This also fails on macOS browsers yoiu need thge twitter-user-id as per mobile – mmmmmm Sep 29 '20 at 09:01
69

Unfortunately, all of the answers provided so far rely on an HTTP redirect.

The direct link is of the form: https://twitter.com/i/web/status/{tweet-status-id}

Jeff Puckett
  • 37,464
  • 17
  • 118
  • 167
  • 3
    this is the only solution that works for both without having to explicitly provide the username (which is volatile if you ask me... nothing like orphaning all of your links at the whim of a user...). that said, does any one know if this is "supported"... it seems hacky... – nokturnal Dec 07 '17 at 00:55
  • 1
    This is also what Twitter itself uses when puts the URL inside the tweet (Streaming API). Very easy without constructing the URL based on UserID. – Maziyar Mar 06 '18 at 11:32
  • 2
    When using Twitter Search API 2, you should use the `conversation_id` field instead of `id` – Guido Jun 03 '21 at 11:20
49

FYI: id_str is the variable you need to call instead of id

id_str should be taken from the tweet object and replaced in https://twitter.com/statuses/[id_str]

FacePalm
  • 10,992
  • 5
  • 48
  • 50
Trevor Jordet
  • 641
  • 6
  • 7
  • 2
    took me a moment to figure that you mean `id_str` should be taken from the tweet object and entered as the ID of sagivo's answer: `https://twitter.com/statuses/[id_str]` – Dominic Sep 15 '16 at 05:43
  • 1
    **This is only necessary for JavaScript** and other environments that doesn't support 64-bit integers – chribsen Dec 21 '16 at 22:37
20

You can use like:

http://twitter.com/itdoesnotmatter/status/[YOURID]

Twitter redirect based on status ID not username.

It works for desktop and mobile.

Seyfi Dertli
  • 209
  • 2
  • 5
7

You can use

'https://www.twitter.com/'+ user.screen_name+'/status/' + id_str
Pawan Kotak
  • 190
  • 1
  • 13
4

I've been tried it. It's work good: - Web : https://twitter.com/statuses/ID - Mobile && Web: https://twitter.com/User_ID/statuses/Tweet_ID

I hope it's helpful for you.