【发布时间】:2021-06-12 13:32:37
【问题描述】:
我正在开发一个 Twitter 应用程序,我想找到一种直接链接到转发的方法。
例如。如果用户 A 发了一条推文,而用户 B 转发了这条推文,我想要一个 URL,它将把我们带到显示转发的用户 B 的个人资料。那个唯一的 URL 是什么?
【问题讨论】:
标签: twitter
我正在开发一个 Twitter 应用程序,我想找到一种直接链接到转发的方法。
例如。如果用户 A 发了一条推文,而用户 B 转发了这条推文,我想要一个 URL,它将把我们带到显示转发的用户 B 的个人资料。那个唯一的 URL 是什么?
【问题讨论】:
标签: twitter
我最近需要获得一个任意转发的链接,该转发对于搜索功能来说太旧了。
这就是我所做的:
访问转发者的时间线
滚动直到找到转推
查看网络监视器,打开对端点/UserTweets的最新请求
要么
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))
…等等:
【讨论】:
在内部,所有转推都是特殊推文。这意味着每个转推也有一个 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 链接。假设您的 Retweet 对象名为 retweet,正确的链接将是(在 JavaScript 中)`https://twitter.com/${retweet.user.screen_name}/status/${retweet.id_str}`。
如果转推是最近的,您可以在用户的个人资料上进行状态搜索 (search/tweets)(即,您必须将 q 参数设置为 from:<username>)以找到转推。不过,您很可能需要交叉检查您想要的推文的 ID 和您要查找的转推的 ID。
但是,如果您尝试获取旧推文的转推 ID,则可能必须使用付费的 Twitter 高级 API。
【讨论】: