在 Twitter API v2 中获取扩展/全文推文 [英] Get extended/full text tweets in Twitter API v2

查看:17
本文介绍了在 Twitter API v2 中获取扩展/全文推文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 Twitter v2 API 几周前刚刚发布,所以这可能只是文档尚未完成的问题.

The new Twitter v2 API was just released a couple of weeks ago, so this may just be an issue of the documentation not being done quite yet.

我想做的是在最近的推文中搜索小狗".并返回所有附加了某种媒体的东西.但是,当我在 Postman 中运行此搜索时,并非所有返回的推文都有 attachments.media_keys.我注意到没有 attachments.media_keys 的是推文,其文本以省略号 ... 结尾.我了解在 v1.1 API 中,通过在查询参数或 tweet.fields=extended_tweet 中指定 tweet_mode=extended 来解决此问题.但是,这些似乎在 v2 API 中不起作用,而且我还没有看到任何有关获取推文全文(以及相关附件)的文档.有谁知道如何在 v2 中做到这一点?

What I am trying to do is search recent tweets for "puppies" and return all that have some kind of media attached. However, when I run this search in Postman, not all of the returned tweets have attachments.media_keys. I noticed that the ones that do not have attachments.media_keys are tweets whose text ends in ellipses .... I understand that in the v1.1 API, this issue is solved by specifying tweet_mode=extended in the query params or tweet.fields=extended_tweet. However, these do not seem to work in the v2 API and I have not seen any documentation about getting the full text of tweets (and the associated attachments). Does anyone know how to do this in v2?

我的 Postman 查询网址:"https://api.twitter.com/2/tweets/search/recent?query=has:media puppies&tweet.fields=attachments&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width"

My Postman query url: "https://api.twitter.com/2/tweets/search/recent?query=has:media puppies&tweet.fields=attachments&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width"

在我的应用中,我使用 Node.js Axios 来执行查询:

In my app, I am using Node.js Axios to perform the query:

var axios = require('axios');

var config = {
  method: 'get',
  url: 'https://api.twitter.com/2/tweets/search/recent?query=has:media puppies&tweet.fields=attachments&expansions=attachments.media_keys&media.fields=duration_ms,height,media_key,preview_image_url,public_metrics,type,url,width',
  headers: { 
    'Authorization': 'Bearer {{my berarer token}}', 
  }
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

推荐答案

好问题,谢谢.我们是 也在 Twitter 开发者论坛上讨论这个问题.

Great question, thank you. We’re discussing this on the Twitter Developer forums as well.

在 API 的 v2 中,我们消除了扩展推文"的概念,因为我们假设所有新应用都理解 280 个字符的概念,因此完整的文本位于推文文本字段中.

In v2 of the API we have eliminated the notion of an "extended Tweet" since we assume that all new apps understand the concept of 280 characters, so the complete text is in the Tweet text field.

您发现的区别在于转推或引用的推文,其中嵌入的文本被截断.这(可能令人惊讶)与 v1.1 以及以前的高级和企业 API 相同.我们正在调查是否要对此进行修改,以及这样做的影响.

The difference you’re finding is in retweets or quoted Tweets where the embedded text is truncated. This is (perhaps surprisingly) the same as v1.1 and the former premium and enterprise APIs as well. We are investigating whether to modify this, and the implications in doing so.

我无意从 Stack 中夺走流量,但您可能会在我们的开发者论坛上找到更多持续更新和信息.谢谢!

I don’t for any means want to take traffic away from Stack, but you might find more ongoing updates and information on our developer forums. Thanks!

这篇关于在 Twitter API v2 中获取扩展/全文推文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆