关于 x
x 是通过 twikit 和用户登录 Cookie 操作真实 X 账号的技能,适合读取动态并管理账号互动。它提供搜索、时间线和趋势等读取命令;所有写操作默认先试运行,确认后才执行。
主要功能
- 01读取账号身份与时间线
- 02搜索帖子和用户
- 03查看趋势与帖子详情
- 04发布帖子和串文
- 05管理点赞、转发与关注
适用场景
- 01查看账号首页时间线
- 02搜索 X 帖子或用户
- 03确认后发布帖子或串文
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ acedatacloud/ skills --skill x安装后在 Claude Code 中输入/x确认已加载。
附带文件scripts/x.py
详细介绍
x — 通过自己的 Cookie 读取和发布 X(Twitter)内容
通过 twikit 调用 X 的内部 Web API,操作用户的真实 X 账号;使用用户通过 ACE 扩展获取的登录 Cookie 进行身份验证。无需官方 API 密钥,也无需付费。
2026-07-06 已使用真实连接账号完成端到端验证,涵盖:加载 Cookie、whoami、搜索推文、搜索用户、首页时间线、趋势、推文详情和发布试运行。实际发布仍需明确确认,验证期间未执行发布。
连接器会将 Cookie jar 注入为环境变量:
X_COOKIES— Cookie 的 JSON 数组(至少需要auth_token和ct0)。机密信息 — 可完全访问账号。切勿回显或打印。
设置 — 验证已随附的 CLI
托管沙盒镜像中已预装 twikit。请勿在运行时执行 pip install;如果导入失败,请报告沙盒镜像缺少 X 技能依赖,然后停止。
python3 -c "import twikit" || { echo "sandbox missing twikit; deploy the sandbox skill dependencies image" >&2; exit 1; }
# $SKILL_DIR can point at another skill loaded this turn — anchor on our own
# script (re-run this setup at the top of every fresh-shell Bash block below).
X="$SKILL_DIR/scripts/x.py"; [ -f "$X" ] || X=$(find /tmp -maxdepth 8 -path '*/skills/*/scripts/x.py' 2>/dev/null | head -1)
[ -f "$X" ] || { echo "x script not found (SKILL_DIR=$SKILL_DIR)" >&2; exit 1; }
python3 "$X" whoami # confirm the shipped CLI can read the authenticated account
读取命令(直接运行)
python3 $X whoami # discover the authenticated account
python3 $X whoami --expect SCREEN_NAME # optional: assert a specific account
python3 $X search --query "ai agents" --product Latest --limit 20 # Top | Latest | Media
python3 $X search-users --query "openai" --limit 10
python3 $X timeline --limit 20 # my home timeline
python3 $X user-tweets --user elonmusk --type Tweets --limit 20 # Tweets|Replies|Media|Likes
python3 $X tweet --id 1234567890123456789 # single tweet detail
python3 $X trends --category trending --limit 20 # trending|for-you|news|sports|entertainment
--user 可接受 @screen_name(@ 可省略)或数字 ID。
首先验证连接
python3 $X whoami
# → {"id": "...", "screen_name": "<the connected handle>", "identity_verified": true, ...}
whoami 会从 X 账号设置中读取已验证账号的 screen name,然后解析其公开个人资料。这样可以避开被 X 的 Cloudflare 拦截的 UserByRestId 端点,且无需信任本地身份 Cookie。
--expect <screen_name> 是可选参数:仅当用户明确指定要以哪个账号进行操作时才传入;如果已连接的 Cookie 属于其他人,命令就会中止。不要自行猜测预期账号名 — 默认直接使用 whoami。
如果发生实际身份验证错误,说明 Cookie 已过期 — 请用户前往 https://studio.acedata.cloud/console/connectors 重新连接。Cloudflare 拦截则不同:重新连接 Cookie 无法解决问题。身份检查请使用 whoami;其他被拦截的端点需要 X_PROXY 或官方 X API。遇到 Cloudflare 拦截或身份验证错误时,不要反复重试。
404 并非身份验证错误。 即使 Cookie 正常,X 的身份端点在所有账号上仍有大约四分之一的调用会返回 404。whoami 已在内部对此类情况进行重试;如果仍然报告 404,请稍等片刻后再次运行 — 不要让用户重新连接。
写入命令 — 受控(末尾没有 --confirm 时为试运行)
所有会更改状态的命令(post、thread、like、unlike、retweet、unretweet、follow、unfollow、delete)在末尾没有 --confirm 时都会进行试运行。只有当 --confirm 是最后一个参数时才会生效,因此推文正文中仅仅包含“--confirm”绝不会导致静默发布。务必先展示试运行结果,针对确切文本取得明确的“是”,然后再使用 --confirm 重新运行。
python3 $X post --text "hello world" # dry-run
python3 $X post --text "hello world" --confirm # LIVE tweet
python3 $X post --text "look at this" --media a.jpg,b.png --confirm # up to 4 images (or 1 video)
python3 $X post --text "great point" --reply-to 123456 --confirm # reply
python3 $X post --text "worth reading" --quote-url https://x.com/u/status/123 --confirm # quote
python3 $X thread --text "1/2 first" --text "2/2 second" --confirm # thread (2+ segments)
python3 $X like --id 123456 --confirm
python3 $X retweet --id 123456 --confirm
python3 $X follow --user elonmusk --confirm
python3 $X delete --id 123456 --confirm # delete one of MY tweets
- 确认后的
post/thread会立即在用户的真实账号上公开发布 — 没有草稿步骤。务必先确认确切文本。 --media接受以逗号分隔的文件路径。X 每条推文最多允许 4 张图片或 1 个视频/GIF;在线程中,媒体仅附加到第一段。
注意事项
- 这是用户真实的 X 账号。 进行任何写入操作前都要确认——帖子会立即公开发布。
- 实时写入未经端到端验证。 读取命令已于 2026-07-06 验证;首次确认写入时请仔细核验。
- twikit 是针对 X 非公开 API 的抓取工具。 X 更改内部端点后,它可能会失效。随附的脚本包含 AceDataCloud 兼容性补丁,用于处理当前的
ondemand.swebpack 分块映射,该映射用于生成事务 ID。如果再次出现Couldn't get KEY_BYTE indices,请将其报告为 X/twikit 上游变动问题——对于这个特定错误,切勿要求用户重新连接 Cookie。 - X 目前会对专用的
UserMedia查询返回依赖项错误。CLI 会回退到常规 Tweets 时间线,并在本地筛选媒体帖子;出现这种情况时,响应中会包含一个fallback字段。 - 服务条款 / 速率限制 / 封禁风险。 此工具通过 Web API(而非官方 API)执行操作——高频自动化可能导致账号触发速率限制或被暂停。请保持类似人工操作的频率。
- 切勿打印
X_COOKIES——它可提供完整的账号访问权限。 - 此技能有意不提供私信功能。
记录输出
成功发布并获取实时结果 URL 后,请调用内置的
publish_artifact 工具一次,让用户能在 我的输出 中跟踪此交付内容:
publish_artifact(kind="message", channel="x", title="<title>", url="<the REAL returned URL>", status="delivered")
请使用实际返回的 URL,绝不可伪造。每个已发布项目仅调用一次,
且只能在确认交付后调用;如果发布失败,请跳过此步骤(或使用 status="failed")。
参阅 _shared/artifacts.md。