{"record":{"id":"68b26dce41883309","repo":"DIYgod/RSSHub","slug":"cookie-68b26d","errorCode":null,"errorMessage":"缺少知乎用户登录后的 Cookie 值","messagePattern":"缺少知乎用户登录后的 Cookie 值","errorType":"exception","errorClass":"ConfigNotFoundError","httpStatus":null,"severity":"error","filePath":"lib/routes/zhihu/timeline.ts","lineNumber":38,"sourceCode":"        ],\n        requirePuppeteer: false,\n        antiCrawler: true,\n        supportBT: false,\n        supportPodcast: false,\n        supportScihub: false,\n    },\n    name: '用户关注时间线',\n    maintainers: ['SeanChao'],\n    handler,\n    description: `::: warning\n用户关注动态需要登录后的 Cookie 值，所以只能自建，详情见部署页面的配置模块。\n:::`,\n};\n\nasync function handler(ctx) {\n    const cookie = config.zhihu.cookies;\n    if (cookie === undefined) {\n        throw new ConfigNotFoundError('缺少知乎用户登录后的 Cookie 值');\n    }\n    const response = await got({\n        method: 'get',\n        url: 'https://www.zhihu.com/api/v3/moments',\n        headers: {\n            Cookie: cookie,\n        },\n        searchParams: {\n            desktop: true,\n            limit: ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : 15,\n        },\n    });\n    const feeds = response.data.data;\n\n    const urlBase = 'https://zhihu.com';\n    const buildLink = (e) => {\n        if (!e || !e.target || !e.target.type) {\n            return '';","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/routes/zhihu/timeline.ts#L20-L56","documentation":"A `ConfigNotFoundError` thrown by the Zhihu \"following timeline\" (用户关注时间线) route when `config.zhihu.cookies` is `undefined`. This route hits Zhihu's authenticated `/api/v3/moments` endpoint, which requires the cookie of a logged-in account, so a self-hosted RSSHub without that config cannot serve it.","triggerScenarios":"The route is invoked on an RSSHub instance where the `ZHIHU_COOKIES` environment variable / config key was never set. The handler reads `config.zhihu.cookies`, finds it undefined, and aborts before any network call.","commonSituations":"Operator deploys RSSHub but skips the Zhihu cookie config; the env var name is misspelled; the cookie was set in a different config layer (e.g. `.env` not loaded); the cookie expired and was removed rather than refreshed.","solutions":["Set `ZHIHU_COOKIES` in your RSSHub environment to the full `Cookie` header string copied from a logged-in zhihu.com browser session.","Restart/reload RSSHub so the config is picked up, then retry the route.","Refresh the cookie periodically — Zhihu sessions expire, and a stale/empty value will eventually cause auth failures downstream."],"exampleFix":"# before — env missing\n# (ZHIHU_COOKIES not set)\n# after — set in .env or shell\nZHIHU_COOKIES=\"z_c0=2|1:0|...; d_c0=...; _zap=...\"","handlingStrategy":"validation","validationCode":"// Before enabling the route, assert the cookie is configured\nimport config from '@/config';\nfunction ensureZhihuCookie() {\n    if (!config.zhihu.cookies) {\n        throw new Error('Set ZHIHU_COOKIES env var to a logged-in zhihu.com cookie string before using this route.');\n    }\n}","typeGuard":"function hasZhihuCookie(): boolean {\n    return typeof config.zhihu.cookies === 'string' && config.zhihu.cookies.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Set ZHIHU_COOKIES during deployment and verify with a health-check request before relying on the route.","Document the cookie's expiry behavior — refresh it on a schedule.","Use the exact env var name RSSHub expects to avoid silent undefined config."],"tags":["zhihu","config","authentication","cookie","config-not-found"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}