【发布时间】:2021-09-05 19:27:27
【问题描述】:
我正在编写一个关于 Nestjs 的项目,但遇到了问题。这是问题,我需要从 twitter api 按关键字获取最流行的推文,但在 api 版本 2 中我找不到如何请求流行的推文。在 1.1 版本中有一个参数 result_type = Popular,但在 2 版本中没有这样的东西,我只能获取最新的推文。谁知道如何获取热门推文,告诉我怎么做。
async fetchTopTweetsData(keyword: string) {
const cacheValue = await this.cache.get(`${keyword}`)
if (cacheValue) {
return this.cache.get(`${keyword}`)
}
AppLogger.log('Twitter module has been updated')
const accessToken = await this.cache.get('bearerToken')
const twitterClient = new TwitterApi(accessToken.access_token)
const response = await twitterClient.v2.get('tweets/search/recent', {
query: `#${keyword}`,
max_results: 20,
})
await this.cache.set(`${keyword}`, 115)
return this.cache.get(`${keyword}`)
}
【问题讨论】:
-
由于 v2 中没有 API 参数,您需要自己构建一些过滤器,例如在您检索到搜索结果后点赞和转发。
标签: javascript twitter nestjs