代码没有任何错误,但是在YouTube页面上没有任何错误。令牌还可以,我可以看到日志说它已经完成,但在YouTube上什么也没。在YouTube上显示视频需要多少时间?
const Youtube = require("youtube-api"),
fs = require("fs"),
readJson = require("r-json"),
Logger = require("bug-killer"),
prettyBytes = require("pretty-bytes");
// I downloaded the file from OAuth2 -> Download JSON
const CREDENTIALS = readJson(`${__dirname}/credentials.json`);
// Authenticate
let oauth = Youtube.authenticate({
type: "oauth",
client_id: CREDENTIALS.web.client_id,
client_secret: CREDENTIALS.web.client_secret,
redirect_url: CREDENTIALS.web.redirect_uris[0]
});
//the token obtained with getToken.js script
var tokens = readJson(`${__dirname}/tokens.json`);
//set the token
oauth.setCredentials(tokens);
var req = Youtube.videos.insert({
resource: {
snippet: {
title: "Testing",
description: "Test video upload via YouTube API"
},
status: {
privacyStatus: "public"
}
},
part: "snippet,status",
media: {
body: fs.createReadStream("video.mp4")
}
}, (err, data) => {
console.log("Done.");
process.exit();
});
setInterval(function() {
Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);
}, 250);
解决,您必须为Google应用程序启用YouTube API V3。愚蠢的问题。