{"record":{"id":"e8ce8254547b1e5a","repo":"hmjz100/LinkSwift","slug":"br-res-msg-res-msg","errorCode":null,"errorMessage":"提示：<br/>获取分享令牌失败，${res.msg ? \"服务器说：\" + res.msg + \"。\" : \"刷新后再试试吧~\"}","messagePattern":"提示：<br/>获取分享令牌失败，(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"（改）网盘直链下载助手.user.js","lineNumber":8071,"sourceCode":"\t\t\t\t\tcode = this.getShareToken.code;\r\n\t\t\t\t}\r\n\t\t\t\tif (!code && isWaitForType) {\r\n\t\t\t\t\tbase.waitForKeyElements(`input.ant-input[type=text]`, (element) => {\r\n\t\t\t\t\t\tif (element.data('code-listener-bound')) return;\r\n\t\t\t\t\t\telement.data('code-listener-bound', true);\r\n\t\t\t\t\t\telement.on('input', (e) => {\r\n\t\t\t\t\t\t\tconst val = e.target.value.trim();\r\n\t\t\t\t\t\t\tif (val) this.getShareToken.code = val;\r\n\t\t\t\t\t\t});\r\n\t\t\t\t\t});\r\n\t\t\t\t\treturn;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tconst res = await base.post(config.$guangya.api.getShareToken, { \"shareId\": shareId, \"code\": code }, { \"Authorization\": `${token.credentials?.token_type} ${token.credentials?.access_token}`, \"Content-Type\": \"application/json\", \"X-Captcha-Token\": token.captcha.captcha_token, \"X-Device-Id\": token.deviceid });\r\n\r\n\t\t\tif (res.data?.accessToken) return res.data.accessToken;\r\n\t\t\telse throw new Error(`提示：<br/>获取分享令牌失败，${res.msg ? \"服务器说：\" + res.msg + \"。\" : \"刷新后再试试吧~\"}`);\r\n\t\t},\r\n\t\tasync getFileUrl(item, index, token, shareToken) {\r\n\t\t\ttry {\r\n\t\t\t\tlet res;\r\n\t\t\t\tif (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };\r\n\t\t\t\tif (shareToken) {\r\n\t\t\t\t\tres = await base.post(config.$guangya.api.getShareLink, { \"fileId\": item.fileId, \"accessToken\": shareToken }, { \"Authorization\": `${token.credentials?.token_type} ${token.credentials?.access_token}`, \"Content-Type\": \"application/json\", \"X-Captcha-Token\": token.captcha.captcha_token, \"X-Device-Id\": token.deviceid });\r\n\t\t\t\t} else {\r\n\t\t\t\t\tres = await base.post(config.$guangya.api.getLink, { \"fileId\": item.fileId }, { \"Authorization\": `${token.credentials?.token_type} ${token.credentials?.access_token}`, \"Content-Type\": \"application/json\", \"X-Captcha-Token\": token.captcha.captcha_token, \"X-Device-Id\": token.deviceid });\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (res.data?.signedURL || res.data?.downloadUrl) {\r\n\t\t\t\t\treturn { index, downloadUrl: res.data?.signedURL ?? res.data?.downloadUrl };\r\n\t\t\t\t} else if (res.code) {\r\n\t\t\t\t\tif (res.code == 9) return { index, downloadUrl: \"获取下载地址失败，服务器说：页面验证过期了，刷新后再获取吧~\" };\r\n\t\t\t\t\tif (res.code == 103) return { index, downloadUrl: \"获取下载地址失败，服务器说：后端 RPC 响应超时。脚本建议：再重新获取一次~\" };\r\n\t\t\t\t\tif (res.code == 207) return { index, downloadUrl: \"获取下载地址失败，服务器说：分享者未打开免登录下载。请登录后下载~\" };\r\n\t\t\t\t} else {\r","sourceCodeStart":8053,"sourceCodeEnd":8089,"githubUrl":"https://github.com/hmjz100/LinkSwift/blob/417ea5e28a3e1a90339710e17356e9fd22b8a34b/（改）网盘直链下载助手.user.js#L8053-L8089","documentation":"Thrown by Guangya's getShareToken after calling the getShareToken API: the response is checked for res.data?.accessToken; if absent, the call is considered failed and the server's res.msg is embedded in the message, with a generic '刷新后再试试吧~' fallback. It means the share-token endpoint did not yield an access token.","triggerScenarios":"POST to config.$guangya.api.getShareToken with {shareId, code} and Authorization/X-Captcha-Token/X-Device-Id headers; response lacks res.data.accessToken — e.g. wrong or missing extraction code, expired share, rejected captcha token, or invalid device id.","commonSituations":"User entered a wrong extraction code for the share; share link expired or was cancelled; captcha token stale so X-Captcha-Token header rejected; server-side rate limiting or API contract change removing data.accessToken.","solutions":["Read res.msg in the thrown message (e.g. code errors) and re-enter the correct extraction code","Refresh the page to obtain a fresh captcha token, then retry","Confirm the share link is still valid and not expired","Update the userscript if the API moved accessToken to a different response path"],"exampleFix":"// caller-side retry on token failure\ntry {\n  shareToken = await getShareToken(shareId, code);\n} catch (e) {\n  await base.sleep(1500);\n  shareToken = await getShareToken(shareId, code); // refreshes captcha state upstream\n}","handlingStrategy":"retry","validationCode":"if (!shareId) throw new Error('缺少 shareId');\nif (!token?.captcha?.captcha_token) { await refreshCaptcha(); }","typeGuard":"function hasAccessToken(res) { return typeof res?.data?.accessToken === 'string' && res.data.accessToken.length > 0; }","tryCatchPattern":"try { shareToken = await getShareToken(shareId, code); } catch (e) { if (e.message.includes('获取分享令牌失败')) { await refreshCaptcha(); shareToken = await getShareToken(shareId, code); } else throw e; }","preventionTips":["Validate the extraction code before calling","Refresh captcha tokens before each share-token request","Check share-link validity/expiry up front","Update response parsing if the API moves accessToken"],"tags":["share-token","authentication","captcha","guangya"],"backgroundTag":"share-token-fetch-failed","analyzedSha":"417ea5e28a3e1a90339710e17356e9fd22b8a34b","analyzedAt":"2026-09-02T18:13:32.837Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}