hmjz100/LinkSwift · error · Error

9019

9019

Error message

提示:<br/>访问令牌已过期,再获取一次吧~<br/>代码:9019

What it means

Baidu's API returned errno 9019, which the script (网盘直链下载助手.user.js:5941) interprets as an expired OAuth access token. It deletes the stored `baidu_access_token` so the next attempt re-authorizes, then throws this error telling the user to obtain a token again. Unlike errno 112, the fix is re-authorization rather than a page refresh.

Source

Thrown at (改)网盘直链下载助手.user.js:5941

				return true;
			});

			for (let i = 0; i < pending.length; i += size) {
				// 当前批次
				const batch = pending.slice(i, i + size);
				const fsids = JSON.stringify(batch.map(item => item.fs_id));

				const url = new URL(config.$baidu.api.getLink);
				url.searchParams.set("fsids", fsids);
				url.searchParams.set("access_token", token);

				const res = await base.get(url, { "User-Agent": config.$baidu.api.ua.downloadLink });

				if (!res || res.errno !== 0 || !res.list) {
					if (res.errno === 112) throw new Error("提示:<br/>页面已过期,请刷新后重试~<br/>代码:" + res.errno);
					if (res.errno === 9019) {
						base.delValue("baidu_access_token");
						throw new Error("提示:<br/>访问令牌已过期,再获取一次吧~<br/>代码:" + res.errno);
					}
					if (res.errno || res.errmsg) {
						batch.forEach(item => item.dlink = `获取下载地址失败,${(res.errno || res.errmsg) ? "服务器说:" + (res.errno && res.errmsg ? res.errno + " - " + res.errmsg : (res.errmsg || res.errno)) + "。" : "刷新后再试试吧~"}`);
					} else {
						throw new Error("提示:<br/>获取下载链接失败,刷新网页后再试试吧~");
					}
				}

				batch.forEach(_item => {
					const item = res.list.find(li => li.fs_id == _item.fs_id);
					if (item) {
						Object.assign(_item, item);
						temp.glinks.push({ id: _item.fs_id, expires: (Date.now() + 4 * 60 * 60 * 1000), data: item });
					}
				});

				proc += res.list.length;
				$doc.find(".swal2-html-container").html(`已获取 ${proc} / ${items.length} 个链接`);

View on GitHub (pinned to 417ea5e28a)

Solutions

  1. Re-run the script's Baidu authorization flow to mint and store a fresh access_token (the script already cleared the old one).
  2. Retry the download-link fetch after re-authorization; the token is removed automatically on 9019.
  3. If re-auth keeps failing, verify the script's Baidu app key/secret config matches a still-valid OAuth app.
  4. Clear userscript storage for the site (GM storage) if a bad token persists despite delValue.
Defensive patterns

Strategy: retry

Validate before calling

const token = base.getValue("baidu_access_token");
if (!token) { /* run the authorization flow to obtain a fresh access_token first */ }

Type guard

function isBaiduTokenExpired(res) { return res && res.errno === 9019; }

Try / catch

try {
  await fetchBaiduDownloadLinks(batch);
} catch (e) {
  if (String(e.message).includes("代码:9019")) {
    base.delValue("baidu_access_token");
    await reauthorizeBaidu();      // obtain new token
    return fetchBaiduDownloadLinks(batch); // retry once
  }
  throw e;
}

Prevention

When it happens

Trigger: Any call to the Baidu download-link API while the cached `baidu_access_token` is invalid/expired/revoked — e.g. token expired after its lifetime, Baidu revoked it, or the stored token was corrupted or issued to a different app key.

Common situations: Using the script days after the last authorization; reauthorizing on another device/browser which invalidates the old token; Baidu risk-control revoking tokens; a stale token left in userscript storage after script/config updates.

Related errors


AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02). Data as JSON: /api/errors/a1713367e10ef236. Report an issue: GitHub.