jackwener/OpenCLI · error · CommandExecutionError

获取关注列表失败: ${payload.message} (${payload.code})

Error message

获取关注列表失败: ${payload.message} (${payload.code})

What it means

The followings API (api.bilibili.com/x/relation/followings) returned code!==0, so the list could not be fetched; the error surfaces the API's own message and numeric code. Common codes: -400 bad vmid, -403 not-logged-in, -352/-412 risk control, -352 privacy settings.

Source

Thrown at clis/bilibili/following.js:29

    args: [
        { name: 'uid', positional: true, required: false, help: '目标用户 ID(默认为当前登录用户)' },
        { name: 'page', type: 'int', required: false, default: 1, help: '页码' },
        { name: 'limit', type: 'int', required: false, default: 50, help: '每页数量 (最大 50)' },
    ],
    columns: ['mid', 'name', 'sign', 'following', 'fans'],
    func: async (page, kwargs) => {
        if (!page)
            throw new CommandExecutionError('Browser session required for bilibili following');
        // 1. Resolve UID (default to self)
        const uid = kwargs.uid
            ? await resolveUid(page, kwargs.uid)
            : await getSelfUid(page);
        const pn = kwargs.page ?? 1;
        const ps = Math.min(kwargs.limit ?? 50, 50);
        // 2. Fetch following list (standard Cookie API, no Wbi signing needed)
        const payload = await fetchJson(page, `https://api.bilibili.com/x/relation/followings?vmid=${uid}&pn=${pn}&ps=${ps}&order=desc`);
        if (payload.code !== 0) {
            throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);
        }
        const list = payload.data?.list || [];
        if (list.length === 0) {
            return [{ mid: '-', name: `共 ${payload.data?.total ?? 0} 人关注,当前页无数据`, sign: '', following: '', fans: '' }];
        }
        // 3. Map to output
        return list.map((u) => ({
            mid: u.mid,
            name: u.uname,
            sign: (u.sign || '').slice(0, 40),
            following: u.attribute === 6 ? '互相关注' : '已关注',
            fans: u.official_verify?.desc || '',
        }));
    },
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Re-login to refresh cookies if the code indicates auth failure (-101/-403).
  2. If the target hides their list, there is no workaround — use a different uid or inform the user.
  3. Slow down / add delays if -412/-352; retry after waiting.
  4. Validate the uid is numeric and exists before querying.

Example fix

// before
const payload = await fetchJson(page, url);
if (payload.code !== 0) throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);
// after
const payload = await fetchJson(page, url);
if (payload.code === -101 || payload.code === -403) throw new Error('登录已过期,请重新登录');
if (payload.code !== 0) throw new CommandExecutionError(`获取关注列表失败: ${payload.message} (${payload.code})`);
Defensive patterns

Strategy: retry

Validate before calling

if (!/^\d+$/.test(String(uid))) throw new Error(`vmid must be numeric: ${uid}`);
if (!(await isLoggedIn(page))) throw new Error('login required for followings API');

Type guard

function isFollowingsPayload(p) {
  return typeof p === 'object' && p !== null && p.code === 0 && Array.isArray(p.data?.list);
}

Try / catch

const payload = await fetchJson(page, url);
if (payload.code !== 0) {
  if ([-412, -352].includes(payload.code)) return retryWithBackoff(() => followingCommand(page, kwargs));
  if ([-101, -403].includes(payload.code)) throw new Error('session expired; re-login required');
  throw new Error(`cannot list followings of ${uid}: ${payload.message} (${payload.code})`);
}

Prevention

When it happens

Trigger: Querying a uid whose followings list is private, an invalid vmid, an unauthenticated/expired cookie session, or Wbi/risk-control rejection.

Common situations: Target user hid their following list (privacy setting), cookies expired mid-script, scraping at high rate triggering -412, or page number beyond the visible range with restricted access.

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/8e8b6c2f543083e5. Report an issue: GitHub.