【问题标题】:Direct link to Twitter retweet直接链接到 Twitter 转推
【发布时间】:2021-06-12 13:32:37
【问题描述】:

我正在开发一个 Twitter 应用程序,我想找到一种直接链接到转发的方法。

例如。如果用户 A 发了一条推文,而用户 B 转发了这条推文,我想要一个 URL,它将把我们带到显示转发的用户 B 的个人资料。那个唯一的 URL 是什么?

【问题讨论】:

    标签: twitter


    【解决方案1】:

    我最近需要获得一个任意转发的链接,该转发对于搜索功能来说太旧了。

    这就是我所做的:

    1. 打开Network Monitor

    2. 访问转发者的时间线

    3. 滚动直到找到转推

    4. 查看网络监视器,打开对端点/UserTweets的最新请求

    5. 要么

      • 转到“响应”选项卡并手动筛选其 JSON 以获取 id_str 以制作 URL:

      • 或者,将以下内容粘贴到控制台中,然后右键单击响应,“复制...响应”,然后返回控制台按 Enter:

      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))
      

    等等

    https://twitter.com/ThePSF/status/1398372497741946884

    【讨论】:

      【解决方案2】:

      在内部,所有转推都是特殊推文。这意味着每个转推也有一个 ID(存储在 Tweet 对象根的 idid_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。

      【讨论】:

        猜你喜欢
        • 2018-12-17
        • 1970-01-01
        • 2018-11-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-11
        • 2011-08-04
        • 1970-01-01
        相关资源
        最近更新 更多