RSSHub icon indicating copy to clipboard operation
RSSHub copied to clipboard

Twitter user bug

Open 0xcathiefish opened this issue 4 months ago • 4 comments

路由地址

/twitter/user/:id/:routeParams?

完整路由地址

/twitter/user/elonmusk

相关文档

https://docs.rsshub.app/zh/routes/social-media#user-timeline

预期是什么?

正常返回tweet

实际发生了什么?

报错404,但是之前是没问题的,有些账户现在也没问题,但是有些账户已经无法获取?

FetchError: [GET] "https://x.com/i/api/graphql/Yka-W8dz7RaEuQNkroPkYw/UserByScreenName?features=%7B%22hidden_profile_subscriptions_enabled%22%3Atrue%2C%22rweb_tipjar_consumption_enabled%22%3Atrue%2C%22responsive_web_graphql_exclude_directive_enabled%22%3Atrue%2C%22verified_phone_label_enabled%22%3Afalse%2C%22subscriptions_verification_info_is_identity_verified_enabled%22%3Atrue%2C%22subscriptions_verification_info_verified_since_enabled%22%3Atrue%2C%22highlights_tweets_tab_ui_enabled%22%3Atrue%2C%22responsive_web_twitter_article_notes_tab_enabled%22%3Atrue%2C%22subscriptions_feature_can_gift_premium%22%3Atrue%2C%22creator_subscriptions_tweet_preview_api_enabled%22%3Atrue%2C%22responsive_web_graphql_skip_user_profile_image_extensions_enabled%22%3Afalse%2C%22responsive_web_graphql_timeline_navigation_enabled%22%3Atrue%7D&fieldToggles=%7B%22withAuxiliaryUserLabels%22%3Afalse%7D&variables=%7B%22screen_name%22%3A%22elonmusk%22%2C%22withSafetyModeUserFields%22%3Atrue%7D": 404 Not Found

部署

自建

部署相关信息

Ubuntu 24.04, image: diygod/rsshub

额外信息

error: Error in /twitter/user/elonmusk: FetchError: [GET] "https://x.com/i/api/graphql/Yka-W8dz7RaEuQNkroPkYw/UserByScreenName?features=%7B%22hidden_profile_subscriptions_enabled%22%3Atrue%2C%22rweb_tipjar_consumption_enabled%22%3Atrue%2C%22responsive_web_graphql_exclude_directive_enabled%22%3Atrue%2C%22verified_phone_label_enabled%22%3Afalse%2C%22subscriptions_verification_info_is_identity_verified_enabled%22%3Atrue%2C%22subscriptions_verification_info_verified_since_enabled%22%3Atrue%2C%22highlights_tweets_tab_ui_enabled%22%3Atrue%2C%22responsive_web_twitter_article_notes_tab_enabled%22%3Atrue%2C%22subscriptions_feature_can_gift_premium%22%3Atrue%2C%22creator_subscriptions_tweet_preview_api_enabled%22%3Atrue%2C%22responsive_web_graphql_skip_user_profile_image_extensions_enabled%22%3Afalse%2C%22responsive_web_graphql_timeline_navigation_enabled%22%3Atrue%7D&fieldToggles=%7B%22withAuxiliaryUserLabels%22%3Afalse%7D&variables=%7B%22screen_name%22%3A%22elonmusk%22%2C%22withSafetyModeUserFields%22%3Atrue%7D": 404 Not Found

这不是重复的 issue

  • [x] 我已经搜索了 现有 issue,以确保该错误尚未被报告。

0xcathiefish avatar Aug 18 '25 07:08 0xcathiefish

Searching for maintainers:
  • /twitter/user/:id/:routeParams?: @DIYgod @yindaheng98 @Rongronggg9 @CaoMeiYouRen @pseudoyu

To maintainers: if you are not willing to be disturbed, list your username in scripts/workflow/test-issue/call-maintainer.js. In this way, your username will be wrapped in an inline code block when tagged so you will not be notified.

If all routes can not be found, the issue will be closed automatically. Please use NOROUTE for a route-irrelevant issue or leave a comment if it is a mistake. 如果所有路由都无法匹配,issue 将会被自动关闭。如果 issue 和路由无关,请使用 NOROUTE 关键词,或者留下评论。我们会重新审核。

github-actions[bot] avatar Aug 18 '25 07:08 github-actions[bot]

Hi @0xcathiefish! I'm Dosu and I’m helping the RSSHub team.

这个 404 问题很可能是 Twitter(X)最近调整了 API 或加强了反爬虫措施,导致部分账号(尤其是高关注度或特殊账号)无法通过 RSSHub 的 /twitter/user/:id 路由正常获取内容。RSSHub 目前通过 Twitter 的内部 GraphQL API(如 UserByScreenName)获取数据,但这些接口随时可能被 Twitter 限制或变更,出现 404 或内容缺失的情况相关说明

常见的解决方法有:配置多个不同账号的 TWITTER_AUTH_TOKEN(用逗号分隔),定期轮换 token,降低请求频率,监控日志中的 Twitter 相关错误,但这些都不能彻底解决,因为 Twitter 的反爬虫和风控机制在不断变化经验分享

如果只是部分账号无法获取,可能是这些账号被 Twitter 限制了 API 访问(如隐私设置、保护账号、特殊用户等),或者当前 token 已被风控。可以尝试更换 token 或用其他账号测试。

另一个临时方案是使用 RSSHub 新增的 /sotwe/user/:id 路由(通过 sotwe.com 第三方服务抓取 Twitter 内容),虽然不是官方 API,但可以作为备选PR说明

核心代码和参数配置可参考官方文档源码

目前没有永久解决办法,建议关注 RSSHub 仓库的相关 issue 和 PR,及时调整 token 或使用第三方抓取方案。

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 18 '25 07:08 dosubot[bot]

@dosu 这个好像也用不了?

SyntaxError: Unexpected token 'J', "Just a mom"... is not valid JSON

Route: /sotwe/user/:id
Git Hash: b630afc5
Git Date: Thu, 14 Aug 2025 03:05:15 GMT

0xcathiefish avatar Aug 18 '25 09:08 0xcathiefish

这个错误是因为 /sotwe/user/:id 路由期望从 sotwe.com 获取 JSON 数据,但实际收到的是普通文本或 HTML(比如 "Just a mom..."),导致 JSON.parse 解析失败并抛出 SyntaxError。根本原因通常是 sotwe.com API 响应格式变了、被反爬虫拦截、或者目标账号不存在/被限制。

目前 RSSHub 这部分代码没有做异常处理,遇到非 JSON 响应就会直接报错(源码细节)。建议:

  1. 检查你能否直接访问 https://www.sotwe.com/api/v3/user/你的id/,确认不是被墙或被反爬虫拦截。
  2. 可以尝试其他 Twitter 账号,判断是不是个别账号被 sotwe.com 限制。
  3. 如果你有能力修改代码,建议在 JSON.parse 前加 try-catch,并在 catch 里返回更友好的错误提示(比如“sotwe.com 响应异常,可能被反爬虫或接口变动”),这样不会让整个路由崩溃。
  4. 关注 sotwe.com 是否近期有结构变动或反爬升级,或者等待 RSSHub 后续修复。

这个问题和之前 zaobao 路由遇到的 JSON 解析错误类似,都是第三方接口变动导致的,可以参考 相关修复经验

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

dosubot[bot] avatar Aug 18 '25 09:08 dosubot[bot]