【发布时间】:2021-07-09 13:28:36
【问题描述】:
我要做什么
我想将我的代码每天生成的视频自动上传到我的 YouTube 频道。它应该上传视频文件并添加缩略图。
出了什么问题
当我让我的代码上传视频时,视频可以正常播放并且一切正常,但是视频有一个限制,导致它被锁定为私有。没有提供进一步的信息,也无法上诉。我尝试上传为未列出的,之后一切似乎都很好。但是,当我手动将其设置为公开时,即使等待 12 小时后,视频仍会再次锁定为私密。
说明问题的视频:
如何避免此问题并确保人们可以看到视频?我找不到任何违反 YouTube 条款和政策的内容。当我手动上传完全相同的视频时,一切正常。
我的代码
我将 google-api-nodejs-client 与 OAuth2 一起使用。我生成了身份验证 URL:
const authUrl = oauth2Client.generateAuthUrl({
access_type: "offline",
scope: [
"https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.upload",
"https://www.googleapis.com/auth/youtube.readonly"
];
});
上传视频代码:
youtube.videos.insert(
{
auth: auth,
part: "snippet,contentDetails,status",
resource: {
snippet: {
title: "Title goes here",
description: "Description goes here",
tags: ["tags", "go", "here"],
},
status: {
privacyStatus: "private",
selfDeclaredMadeForKids: false,
},
},
media: {
body: fs.createReadStream("./video.avi"),
},
},
async (error, data) => {
if (error)
return reject(error);
}
);
更改缩略图的代码:
youtube.thumbnails.set(
{
auth: auth,
videoId: videoId,
media: {
mimeType: "image/jpeg",
body: fs.readFileSync(`./thumbnail.png`)
},
},
(err, thumbResponse) => {
if (err) {
console.log("Error response");
console.log(err);
}
console.log(thumbResponse);
}
);
【问题讨论】:
-
这是您问题的答案:Using Youtube Data API makes my videos private on upload。在那里您可以找到来自 Google 官方来源的报价。
标签: node.js google-api youtube-api youtube-data-api google-api-nodejs-client