node.js - 调用 YouTube 插入 API 时缺少凭据
问题描述
我想使用 API 密钥而不是 OAuth 令牌从 YouTube v3 lib 调用插入 API。代码片段如下所示:
await google
.youtube("v3")
.videos.insert({
key: "my-youtube-api-key",
part: "id,snippet,status",
notifySubscribers: false,
requestBody: {
snippet: {
title: "Test video title",
description: "Test video description",
},
status: {
privacyStatus: "public",
},
},
media: {
body: fs.createReadStream(filePath),
},
})
.catch((err) => {
console.log("Upload to YouTube failed", err);
return null;
});
但是,我遇到错误代码 401,消息是:
code: 401,
errors: [
{
message: 'Login Required.',
domain: 'global',
reason: 'required',
location: 'Authorization',
debugInfo: 'Authentication error: missing credentials.',
locationType: 'header'
}
]
我该如何解决这个问题?不支持 API 密钥吗?谢谢!
解决方案
根据文档Videos.insert
,在端点上使用 API 密钥是不够的;您必须获得适当授权才能调用此端点:
授权
此请求需要至少具有以下范围之一的授权(阅读有关身份验证和授权的更多信息)。
范围
https://www.googleapis.com/auth/youtube.upload
https://www.googleapis.com/auth/youtube
https://www.googleapis.com/auth/youtubepartner
https://www.googleapis.com /auth/youtube.force-ssl
推荐阅读
- html - 如何更改特定的网格列?
- python - 如何将 2 列转换为目标索引
- python-3.x - 由 AWS Managed Key 加密的 AWS Cross Account S3 PutObject 中的访问被拒绝问题
- python - Python 图像窗口在 Mac 上未正确关闭
- java - 如何在布局活动中显示随机声音结果的值以便可以播放
- javascript - 如何在 react-bootstrap 网格中正确使用引导拉伸?
- vb.net - 在 vb.net 中搜索时突出显示文本
- python - 使用正则表达式和字典重命名数据框列
- python - 绝对路径导入中没有名为“app”的模块
- flutter-assetimage - AssetImage 图片未显示