hmjz100/LinkSwift · error · Error
提示:<br/>获取分享令牌失败,${res.msg ? "服务器说:" + res.msg + "。" : "刷新后再
Error message
提示:<br/>获取分享令牌失败,${res.msg ? "服务器说:" + res.msg + "。" : "刷新后再试试吧~"} What it means
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.
Source
Thrown at (改)网盘直链下载助手.user.js:8071
code = this.getShareToken.code;
}
if (!code && isWaitForType) {
base.waitForKeyElements(`input.ant-input[type=text]`, (element) => {
if (element.data('code-listener-bound')) return;
element.data('code-listener-bound', true);
element.on('input', (e) => {
const val = e.target.value.trim();
if (val) this.getShareToken.code = val;
});
});
return;
}
}
const 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 });
if (res.data?.accessToken) return res.data.accessToken;
else throw new Error(`提示:<br/>获取分享令牌失败,${res.msg ? "服务器说:" + res.msg + "。" : "刷新后再试试吧~"}`);
},
async getFileUrl(item, index, token, shareToken) {
try {
let res;
if (item.downloadUrl) return { index, downloadUrl: item.downloadUrl };
if (shareToken) {
res = 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 });
} else {
res = 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 });
}
if (res.data?.signedURL || res.data?.downloadUrl) {
return { index, downloadUrl: res.data?.signedURL ?? res.data?.downloadUrl };
} else if (res.code) {
if (res.code == 9) return { index, downloadUrl: "获取下载地址失败,服务器说:页面验证过期了,刷新后再获取吧~" };
if (res.code == 103) return { index, downloadUrl: "获取下载地址失败,服务器说:后端 RPC 响应超时。脚本建议:再重新获取一次~" };
if (res.code == 207) return { index, downloadUrl: "获取下载地址失败,服务器说:分享者未打开免登录下载。请登录后下载~" };
} else {
View on GitHub (pinned to 417ea5e28a)
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
Example fix
// caller-side retry on token failure
try {
shareToken = await getShareToken(shareId, code);
} catch (e) {
await base.sleep(1500);
shareToken = await getShareToken(shareId, code); // refreshes captcha state upstream
} Defensive patterns
Strategy: retry
Validate before calling
if (!shareId) throw new Error('缺少 shareId');
if (!token?.captcha?.captcha_token) { await refreshCaptcha(); } Type guard
function hasAccessToken(res) { return typeof res?.data?.accessToken === 'string' && res.data.accessToken.length > 0; } Try / catch
try { shareToken = await getShareToken(shareId, code); } catch (e) { if (e.message.includes('获取分享令牌失败')) { await refreshCaptcha(); shareToken = await getShareToken(shareId, code); } else throw e; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [光鸭云盘] 获取分享令牌失败
- 错误:<br/>令牌刷新失败,${res?.error_description || res?.error || "未知
- 错误:<br/>请先登录网盘后再获取文件呢~
- [迅雷云盘] 获取令牌失败
AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02).
Data as JSON: /api/errors/e8ce8254547b1e5a.
Report an issue: GitHub.