Skip to content

archive ​

全量镜像一个账号:时间线、转发、收藏、点赞、历史评论、图片墙、视频。产出 ArchiveItem 流,带 checkpoint。

方法返回
streamArchive(uid, options?)AsyncIterableIterator<ArchiveItem>
streamUsersArchive(uids, options?)AsyncIterableIterator<ArchiveUserItem>

访客调用抛 CONFIG_INVALID,匿名列表只有第一页,边界见 范围与限制。

streamArchive(uid, options?) ​

ts
for await (const item of sdk.archive.streamArchive('1111681197', {
  includeReposts: true,
  includeFavorites: true,
  includeLikes: true,
  includeCommentHistory: true,
  includeImages: true,
  includeVideos: true,
  concurrency: 3,
})) {
  if (item.tweet) await persist(item.tweet)
  if (item.asset) await saveMedia(item.asset)
  if (item.comment) await persistComment(item.comment)
  await saveCheckpoint(item.checkpoint)
}

ArchiveItem ​

字段类型说明
schemaVersionTweetContractVersionITweet 契约版本,当前 2
source'timeline' | 'repost' | 'favorite' | 'like' | 'comment' | 'image' | 'video'条目来源
mblogIdstring?微博字母 id;图片项可能缺省
tweetITweet?归一化微博;source: 'image' 时缺省
assetIUserMediaAsset?图片 / 视频项
commentITweetComment?source: 'comment' 时的历史评论
schemaDigestunknownraw 结构快照,用于检测上游字段漂移
checkpointArchiveCheckpoint保存它即可续跑

续跑 ​

投递语义为 at-least-once:checkpoint 记录最后一条已完整处理的项,中断后可能重复边界 1 条。

  • 图片墙 / 视频瀑布按整页写回游标,续跑会重放整页。
  • 消费端按 mblogId / asset.id 幂等去重。
ts
let checkpoint = await loadCheckpoint()

for await (const item of sdk.archive.streamArchive(uid, { checkpoint })) {
  await persist(item)
  checkpoint = item.checkpoint
  await saveCheckpoint(checkpoint)
}

选项 ​

选项默认说明
includeRepoststrue归档每条微博的转发
includeFavoritestrue收藏(账号级)
includeLikesfalse我赞过的微博(按目标 uid)
includeCommentHistoryfalse历史评论(账号级)
includeImagesfalse图片墙(item.asset,可能无 tweet)
includeVideosfalse视频瀑布(同时有 tweet 与 asset)
count20timeline 每页条数
maxPagesPerPhase不限每阶段最多翻页数
concurrency3页内预取并发,限制在 1–8;1 完全串行
checkpoint无断点续传
onRaw无归一化前的 raw 通过该回调传出,ArchiveItem 只带归一化字段
timelineSource'mymblog''mymblog' 翻到底 + 日期切片;'search' 直接日期切片
includeDateSlicestruemymblog 翻到底后用 searchProfile 补齐
since / until微博上线日 / 现在日期切片边界(unix 秒)
searchQuery无日期切片内的关键词过滤
sliceWindow30 天自适应切片初始窗口(秒)
maxSliceItems800单切片最多条数,超过则对半缩小窗口
includeCommentsfalse拉取并挂载评论到 tweet.comments
maxCommentPagesPerTweet不限每条微博最多评论页数
commentCount20评论每页条数
onProgress无ArchiveProgress 回调
onItemError无返回 abort / skip / retry
repostErrorPolicyskip转发页失败策略
commentsErrorPolicyskip评论失败策略
likesErrorPolicyabort点赞页失败策略
commentHistoryErrorPolicyabort历史评论失败策略
imagesErrorPolicyabort图片墙失败策略
videosErrorPolicyabort视频瀑布失败策略
incremental无增量:since / stopAtMblogId / skipPinned
originalOnlyfalse只归档原创,跳过内联转发
maxRetries1可重试错误的最大重试次数
retryDelayMs0重试间隔

ArchiveCheckpoint ​

字段说明
uid归档用户
phasetimeline / likes / comments / favorites / images / videos / done
pagemymblog 当前页(恢复时重跑该页)
lastTimelineMblogId已完整处理的最后一条微博
favoritesPage / likesPage收藏 / 点赞当前页
imagesCursor / videosCursor媒体下一页游标
commentHistoryCursor历史评论 max_id
sliceEnd / slicePage / sliceWindow日期切片游标(存在 sliceEnd 即处于切片阶段)

streamUsersArchive(uids, options?) ​

串行归档多个 uid,按用户注入 checkpoint / 增量:

ts
for await (const { uid, item } of sdk.archive.streamUsersArchive(['111', '222'], {
  includeLikes: true,
  getCheckpoint: uid => state[uid],
  getIncremental: uid => ({ stopAtMblogId: lastSeen[uid], skipPinned: true }),
  onUserStart: uid => console.log('start', uid),
  onUserDone: (uid, count) => console.log('done', uid, count),
  onUserError: (uid, error) => 'skip',
})) {
  await persist(uid, item)
}

在单账号选项基础上增加:getCheckpoint、getIncremental、onUserStart、onUserDone、onUserError(默认 abort)。

边界 ​

  • includeFavorites / includeCommentHistory 只对登录账号有效;归档他人会抛 CONFIG_INVALID。
  • timelineSource: 'search' 且未注入 searchByDate 时,首次迭代抛 CONFIG_INVALID。
  • 日期切片串行枚举:searchProfile 的 page > 1 复用最近一次 page=1 的窗口,并发枚举会互相覆盖。

CLI ​

bash
weibo-cli archive <uid> --state .weibo-archive-state.json
weibo-cli archive --uid-file uids.txt --state .weibo-archive-state.json
weibo-cli archive <uid> --likes --comment-history --images --videos

只读公开数据;请遵守微博服务条款与隐私边界。