{"record":{"id":"a1713367e10ef236","repo":"hmjz100/LinkSwift","slug":"9019","errorCode":"9019","errorMessage":"提示：<br/>访问令牌已过期，再获取一次吧~<br/>代码：9019","messagePattern":"提示：<br/>访问令牌已过期，再获取一次吧~<br/>代码：9019","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":5941,"sourceCode":"\t\t\t\treturn true;\r\n\t\t\t});\r\n\r\n\t\t\tfor (let i = 0; i < pending.length; i += size) {\r\n\t\t\t\t// 当前批次\r\n\t\t\t\tconst batch = pending.slice(i, i + size);\r\n\t\t\t\tconst fsids = JSON.stringify(batch.map(item => item.fs_id));\r\n\r\n\t\t\t\tconst url = new URL(config.$baidu.api.getLink);\r\n\t\t\t\turl.searchParams.set(\"fsids\", fsids);\r\n\t\t\t\turl.searchParams.set(\"access_token\", token);\r\n\r\n\t\t\t\tconst res = await base.get(url, { \"User-Agent\": config.$baidu.api.ua.downloadLink });\r\n\r\n\t\t\t\tif (!res || res.errno !== 0 || !res.list) {\r\n\t\t\t\t\tif (res.errno === 112) throw new Error(\"提示：<br/>页面已过期，请刷新后重试~<br/>代码：\" + res.errno);\r\n\t\t\t\t\tif (res.errno === 9019) {\r\n\t\t\t\t\t\tbase.delValue(\"baidu_access_token\");\r\n\t\t\t\t\t\tthrow new Error(\"提示：<br/>访问令牌已过期，再获取一次吧~<br/>代码：\" + res.errno);\r\n\t\t\t\t\t}\r\n\t\t\t\t\tif (res.errno || res.errmsg) {\r\n\t\t\t\t\t\tbatch.forEach(item => item.dlink = `获取下载地址失败，${(res.errno || res.errmsg) ? \"服务器说：\" + (res.errno && res.errmsg ? res.errno + \" - \" + res.errmsg : (res.errmsg || res.errno)) + \"。\" : \"刷新后再试试吧~\"}`);\r\n\t\t\t\t\t} else {\r\n\t\t\t\t\t\tthrow new Error(\"提示：<br/>获取下载链接失败，刷新网页后再试试吧~\");\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\r\n\t\t\t\tbatch.forEach(_item => {\r\n\t\t\t\t\tconst item = res.list.find(li => li.fs_id == _item.fs_id);\r\n\t\t\t\t\tif (item) {\r\n\t\t\t\t\t\tObject.assign(_item, item);\r\n\t\t\t\t\t\ttemp.glinks.push({ id: _item.fs_id, expires: (Date.now() + 4 * 60 * 60 * 1000), data: item });\r\n\t\t\t\t\t}\r\n\t\t\t\t});\r\n\r\n\t\t\t\tproc += res.list.length;\r\n\t\t\t\t$doc.find(\".swal2-html-container\").html(`已获取 ${proc} / ${items.length} 个链接`);\r","sourceCodeStart":5923,"sourceCodeEnd":5959,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L5923-L5959","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run the script's Baidu authorization flow to mint and store a fresh access_token (the script already cleared the old one).","Retry the download-link fetch after re-authorization; the token is removed automatically on 9019.","If re-auth keeps failing, verify the script's Baidu app key/secret config matches a still-valid OAuth app.","Clear userscript storage for the site (GM storage) if a bad token persists despite delValue."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"const token = base.getValue(\"baidu_access_token\");\nif (!token) { /* run the authorization flow to obtain a fresh access_token first */ }","typeGuard":"function isBaiduTokenExpired(res) { return res && res.errno === 9019; }","tryCatchPattern":"try {\n  await fetchBaiduDownloadLinks(batch);\n} catch (e) {\n  if (String(e.message).includes(\"代码：9019\")) {\n    base.delValue(\"baidu_access_token\");\n    await reauthorizeBaidu();      // obtain new token\n    return fetchBaiduDownloadLinks(batch); // retry once\n  }\n  throw e;\n}","preventionTips":["Re-authorize periodically; Baidu access tokens have a limited lifetime.","Clear the cached baidu_access_token whenever authorization config (app key) changes.","On 9019, always mint a new token before retrying — never retry with the old one.","Watch for re-authorization on other devices revoking the token used here."],"tags":["baidu","oauth","token-expired","api-error"],"backgroundTag":"access-token-expired","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}