hmjz100/LinkSwift · error · Error
[天翼云盘] 获取令牌失败
Error message
[天翼云盘] 获取令牌失败
What it means
Fallback error when getToken() for 天翼云盘 rejects with a non-Error value. The script first tries the cached accessToken from storage; if absent, it calls getToken(), and if that promise rejects with something that isn't an Error instance (string/object/undefined), it is rewrapped as this generic '[天翼云盘] 获取令牌失败' message.
Source
Thrown at (改)网盘直链下载助手.user.js:7369
return { index, downloadUrl: res.fileDownloadUrl };
} else if (res.errorcode == "InvalidSessionKey") {
return { index, downloadUrl: "提示:<br/>请先登录网盘~" };
} else if (res.res_code == "ShareNotFoundFlatDir") {
return { index, downloadUrl: "提示:<br/>请[转存]文件,之后再👉前往[我的网盘]中下载哦~" };
} else {
return { index, downloadUrl: "获取下载地址失败,刷新后再试试吧~" + (res.res_code ? res.res_code : "") };
}
},
async getLink() {
let selects = this.getSelectedList();
if (selects.length === 0) throw new Error("提示:<br/>请勾选要下载的文件哦~");
if (selects.every(item => item.isFolder)) throw new Error("提示:<br/>请打开文件夹后再勾选文件~");
selects = selects.filter(item => !item.isFolder)
$doc.find(".loading-popup .loading-title").html(`令牌获取中`);
$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取状态~</div>`);
const token = base.getStorage("accessToken") || await this.getToken().catch(e => {
if (e instanceof Error) throw e;
throw new Error(e?.message || e || "[天翼云盘] 获取令牌失败");
});
if (!token) {
throw new Error("提示:<br/>请先登录网盘~");
}
$doc.find(".loading-popup .loading-title").html(`令牌获取中`);
$doc.find(".loading-popup .swal2-html-container").html(`<div>获取缓存成功~</div>`);
const batchSize = 15;
let proc = 0;
$doc.find(".loading-popup .loading-title").html(`链接获取中`);
$doc.find(".loading-popup .swal2-html-container").html(`<div>正在获取文件对应的下载链接~</div>`);
for (let i = 0; i < selects.length; i += batchSize) {
const batch = selects.slice(i, i + batchSize);
const queue = [];
batch.forEach((item, localIndex) => {
const globalIndex = i + localIndex;
queue.push(this.getFileUrl(item, globalIndex, token)
.then(val => {
proc++;
View on GitHub (pinned to 417ea5e28a)
Solutions
- Log in to 天翼云盘 in the same browser, then refresh the page and retry.
- Clear the script's stored accessToken and re-trigger token acquisition while logged in.
- Inspect the raw rejection value inside getToken() to see the actual API response (e.g. captcha or risk-control) and handle it.
- Update the userscript if the site changed its login/token endpoint.
Example fix
// before
throw e?.message || e;
// after
const detail = e?.message ?? (typeof e === 'object' ? JSON.stringify(e) : String(e));
throw new Error('[天翼云盘] 获取令牌失败: ' + detail); Defensive patterns
Strategy: try-catch
Validate before calling
if (!base.getStorage('accessToken') && !isLoggedInToTianyi()) {
alert('请先登录天翼云盘~');
return;
} Type guard
function isUsableToken(t) {
return typeof t === 'string' && t.length > 0;
} Try / catch
try {
var token = base.getStorage('accessToken') || await getToken();
} catch (e) {
console.error('getToken原始失败:', e);
throw new Error('[天翼云盘] 获取令牌失败: ' + (e?.message ?? String(e)));
} Prevention
- Log in to 天翼云盘 before running downloads; keep the session cookie alive.
- Log the raw rejection inside getToken() to catch captcha/risk-control responses.
- Clear the cached accessToken after logging out so stale tokens aren't reused.
- Update the userscript after site login-flow changes.
When it happens
Trigger: base.getStorage("accessToken") is empty AND this.getToken() rejects with a non-Error value whose ?message is falsy, in the catch at line 7369.
Common situations: User not logged into 天翼云盘 so token acquisition fails; the login-session cookie expired; the token API returned an unexpected body (captcha, risk-control page) that was rejected raw; network failure during token fetch.
Related errors
- 提示:<br/>请先登录网盘~
- [百度网盘] 获取令牌失败
- AccessTokenInvalid
- 提示:<br/>请先登录网盘后再刷新页面呢~
- 提示:<br/>请先登录网盘~<br/>代码:${res.code}
AI-assisted analysis of hmjz100/LinkSwift@417ea5e28a (2026-09-02).
Data as JSON: /api/errors/e23c8ec6512cd477.
Report an issue: GitHub.