指向特定 tweet 的 Twitter 链接的 URL

我有一些 Javascript,它使用 Twitter API 来获取 tweet。我解析数据并使用 jQuery 为 DOM 生成 HTML。

我想展示的一个方面是“查看这条推”链接——是的,听起来有点傻,但它允许用户获取特定推的 URL。

我正在生成一个带有 href 的标记。 URL 的格式如下:

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

其中花括号中的内容是从 tweet 中提取的实际数据(不,我没有包括花括号)。例如:

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

操作中发生的情况是,这对某些 tweet 有效,但对其他 tweet 无效。对于失败的页面,Twitter 服务器会返回一些内容,说明请求的页面不存在。

我做错什么了吗?

69498 次浏览

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]

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

You can use like:

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

Twitter redirect based on status ID not username.

It works for desktop and mobile.

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}

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.

You can use

'https://www.twitter.com/'+ user.screen_name+'/status/' + id_str