【发布时间】:2021-08-14 06:55:40
【问题描述】:
我不明白为什么一个简单的 fetch 请求通过 Vanilla JS 不成功,但通过 Postman 成功:
const getNotion = () => {
fetch(
"https://api.notion.com/v1/databases/[DBID_HERE]",
{
method: "GET",
headers: {
"Authorization": "Bearer [SECRET_HERE]",
"Notion-Version": "2021-05-11"
}
}
)
.then((response) => response.json())
.then((json) => {
console.log(json);
})
.catch((err) => console.log("Request Failed", err));
};
getNotion();
响应是 Request Failed TypeError: Failed to fetch。 DBID 和 SECRET 都是正确的。
【问题讨论】:
-
请出示相应的邮递员要求
-
您检查过 CORS 问题吗?
-
CORS 问题?这是什么意思?
-
好吧,如果你仔细想想,这并不奇怪,他们不支持来自网页的请求。因为要从网页发出请求,您需要向使用该网页的每个人公开您的凭据。因此,从您的服务器执行对数据库的请求似乎很合乎逻辑,这是一个受保护的环境。
标签: javascript fetch notion-api