You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用rtweet包search_tweets统计历史推文时遇错误求助

问题描述

我在开展研究项目时,需要统计2014、2015等年份特定日期下某关键词的推文数量,使用RStudio中rtweet包的search_tweets函数实现,代码如下:

token <- rtweet::create_token(
  consumer_key = "your_key",    # Consumer API Key
  consumer_secret = "your_secret",  # Consumer API Secret
  access_token = "your_access_token",  # Access token
  access_secret = "your_access_secret"  # Access token secret
)

tweets <- search_tweets(
  "#keyword", 
  since = "2024-09-16", 
  until = "20124-09-19", 
  n = 10000,  # Adjust this depending on the expected number of tweets
  include_rts = FALSE # Exclude retweets if not needed
)

运行后出现错误:

Error in search_params(q, type = type, include_rts = include_rts, geocode = geocode,  :    is.atomic(max_id) && length(max_id) <= 1L is not TRUE

已检查Twitter令牌(token)和速率限制(rate_limit),仅保留关键词与n参数仍报错,请问问题出在哪里?

问题分析与解决
  • 核心错误:日期格式非法:代码中until参数的年份写成了20124,多输入了一个数字2,正确格式应为2024-09-19。非法日期会导致rtweet内部参数解析异常,触发你看到的错误提示。
  • 额外注意事项:
    • 若修正日期后仍报错,检查所有传入search_tweets的参数是否为原子类型(即单个值,而非列表、向量等多元素结构)。
    • 关于你需要的2014、2015年推文统计:免费版Twitter API仅支持获取最近7天的推文,要获取更早的历史推文,必须使用Twitter Academic Research API,同时确保rtweet包配置正确关联该API权限。

内容的提问来源于stack exchange,提问作者Schwa97

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 11:10:58