直接 link 到 Twitter 转发
Direct link to Twitter retweet
我正在开发 Twitter 应用程序,我想找到一种方法 link 直接转推。
例如。如果用户 A 发了一条推文,而用户 B 转推了它,我想要一个 URL 将我们带到显示转推的用户 B 的个人资料。什么是独特的 URL?
在内部,所有转推都只是特殊的推文。这意味着每个 Retweet 也有一个 ID(存储在 Tweet 对象根部的 id
和 id_str
上)。 For proof, here's a Retweet from the Twitter Retweets account.
如果您使用的是推文流(例如 statuses/filter
),您将能够从转推的返回推文对象中获取此 ID。根据 ID,您可以用 https://twitter.com/<username>/status/<retweet id>
构建一个普通的 Twitter link。假设您的 Retweet 对象被命名为 retweet
,正确的 link 将是(在 JavaScript 中)`https://twitter.com/${retweet.user.screen_name}/status/${retweet.id_str}`
.
如果转推是最近的,您可以在用户的个人资料上进行状态搜索 (search/tweets
)(即您必须将 q
参数设置为 from:<username>
)以找到转推。不过,您很可能必须交叉检查所需推文的 ID 和要查找的转推的 ID 才能确定。
但是,如果您尝试获取旧推文的转推 ID,则可能必须使用付费的 Twitter 高级 API。
我最近需要 link 任意转推,该转推对于搜索功能来说太旧了。
这是我所做的:
-
访问转发者的时间线
滚动直到找到转推
查看网络监视器,打开对端点的最新请求/UserTweets
或者
转到“响应”选项卡并手动筛选其 JSON 以获得 id_str
来制作 URL:
或者,将以下内容粘贴到控制台,然后右键单击响应,“复制…响应”,然后return到控制台按回车:
UserTweets = JSON.parse(prompt("Paste the copied Response data:"));
// get the output from that endpoint,
UserTweets
// dig through the packaging,
['data']['user']['result']['timeline']['timeline']['instructions']
// filter out "pinned tweets" metadata,
.filter(cmd => cmd['type'] == "TimelineAddEntries")
// de-batch,
.map(cmd => cmd['entries']).flat()
// filter out "cursor" metadata,
.filter(entry => entry['content']['entryType'] == "TimelineTimelineItem" )
// then dig through a bunch more layers of packaging,
.map(entry => entry['content']['itemContent']['tweet_results']['result'])
// munge the tweets into a more-usable format,
.map(tweet => [tweet['core']['user']['legacy'], tweet['legacy']])
// filter out non-retweets,
.filter(([user, tweet]) => tweet['retweeted_status_result'])
// extract just the RT text and URL of the retweet itself,
.map(([user, tweet]) => [`https://twitter.com/${user['screen_name']}/status/${tweet['id_str']}`, tweet['full_text']])
// print results.
.forEach(([url, rt_text]) => console.log(url, rt_text))
…瞧瞧:
我正在开发 Twitter 应用程序,我想找到一种方法 link 直接转推。
例如。如果用户 A 发了一条推文,而用户 B 转推了它,我想要一个 URL 将我们带到显示转推的用户 B 的个人资料。什么是独特的 URL?
在内部,所有转推都只是特殊的推文。这意味着每个 Retweet 也有一个 ID(存储在 Tweet 对象根部的 id
和 id_str
上)。 For proof, here's a Retweet from the Twitter Retweets account.
如果您使用的是推文流(例如 statuses/filter
),您将能够从转推的返回推文对象中获取此 ID。根据 ID,您可以用 https://twitter.com/<username>/status/<retweet id>
构建一个普通的 Twitter link。假设您的 Retweet 对象被命名为 retweet
,正确的 link 将是(在 JavaScript 中)`https://twitter.com/${retweet.user.screen_name}/status/${retweet.id_str}`
.
如果转推是最近的,您可以在用户的个人资料上进行状态搜索 (search/tweets
)(即您必须将 q
参数设置为 from:<username>
)以找到转推。不过,您很可能必须交叉检查所需推文的 ID 和要查找的转推的 ID 才能确定。
但是,如果您尝试获取旧推文的转推 ID,则可能必须使用付费的 Twitter 高级 API。
我最近需要 link 任意转推,该转推对于搜索功能来说太旧了。
这是我所做的:
访问转发者的时间线
滚动直到找到转推
查看网络监视器,打开对端点的最新请求
/UserTweets
或者
转到“响应”选项卡并手动筛选其 JSON 以获得
id_str
来制作 URL:
或者,将以下内容粘贴到控制台,然后右键单击响应,“复制…响应”,然后return到控制台按回车:
UserTweets = JSON.parse(prompt("Paste the copied Response data:")); // get the output from that endpoint, UserTweets // dig through the packaging, ['data']['user']['result']['timeline']['timeline']['instructions'] // filter out "pinned tweets" metadata, .filter(cmd => cmd['type'] == "TimelineAddEntries") // de-batch, .map(cmd => cmd['entries']).flat() // filter out "cursor" metadata, .filter(entry => entry['content']['entryType'] == "TimelineTimelineItem" ) // then dig through a bunch more layers of packaging, .map(entry => entry['content']['itemContent']['tweet_results']['result']) // munge the tweets into a more-usable format, .map(tweet => [tweet['core']['user']['legacy'], tweet['legacy']]) // filter out non-retweets, .filter(([user, tweet]) => tweet['retweeted_status_result']) // extract just the RT text and URL of the retweet itself, .map(([user, tweet]) => [`https://twitter.com/${user['screen_name']}/status/${tweet['id_str']}`, tweet['full_text']]) // print results. .forEach(([url, rt_text]) => console.log(url, rt_text))
…瞧瞧: