You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用Patreon API时出现401 Unauthorized错误,寻求解决方案

解决Patreon API 401未授权错误的排查方向

我已经查阅资料、浏览官方文档并咨询ChatGPT,但仍未找到修复401错误的方法。以下是我的代码实现:

import express from 'express';
import fetch from 'node-fetch';

const app = express();

const creatorId = 'creator-ID';
const accessToken = 'access-Token';

app.get('/creator', async (req, res) => {
    try {
        const response = await fetch(`https://www.patreon.com/api/oauth2/v2/campaigns/${creatorId}`, {
            headers: {
                'Authorization': `Bearer ${accessToken}`
            }
        });
        const json = await response.json();
        res.json(json);
    } catch (err) {
        res.status(500).json({ error: err.message });
    }
});

app.listen(3000, () => {
    console.log('Server listening on port 3000');
});

错误信息如下:

{"errors":[{"code":1,"code_name":"Unauthorized","detail":"The server could not verify that you are authorized to access the URL requested. You either supplied the wrong credentials (e.g. a bad password), or your browser doesn't understand how to supply the credentials required.","id":"d2b03413-652e-5a35-a0ea-efe87bbd5995","status":"401","title":"Unauthorized"}]}

排查要点

  • 检查AccessToken有效性:确认access-Token是通过正确OAuth2流程获取,未过期且具备访问创作者campaign的权限。Patreon的AccessToken会过期,需及时刷新。
  • 验证CreatorID正确性:确保creator-ID是当前AccessToken对应创作者的正确ID,格式无错误(比如是否为指定的字符串或数字格式)。
  • 请求头格式校验:确认Authorization头格式完全正确,严格遵循Bearer + 空格 + AccessToken的结构,无多余空格或拼写错误。
  • 权限范围确认:获取AccessToken时,是否申请了campaigns相关的权限范围,权限不足会直接返回401。
  • API端点检查:确认请求URL是Patreon API v2的正确端点,无拼写错误。

内容的提问来源于stack exchange,提问作者Tenno

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 11:10:19