【发布时间】:2020-12-11 20:54:51
【问题描述】:
新的 Twitter v2 API 几周前刚刚发布,所以这可能只是文档尚未完成的问题。
我要做的是在最近的推文中搜索“小狗”,然后返回所有附加了某种媒体的推文。但是,当我在 Postman 中运行此搜索时,并非所有返回的推文都有 attachments.media_keys。我注意到没有attachments.media_keys 的是推文,其文本以省略号... 结尾。我了解在 v1.1 API 中,通过在查询参数中指定 tweet_mode=extended 或 tweet.fields=extended_tweet 来解决此问题。但是,这些似乎在 v2 API 中不起作用,而且我还没有看到任何有关获取推文全文(以及相关附件)的文档。有谁知道如何在 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"
在我的应用中,我使用 Node.js Axios 来执行查询:
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);
});
【问题讨论】: