我正在使用Node.Js(here is the link)上传Youtube视频的教程,它效果很好。唯一的问题是,在完成脚本后,我找不到我上传的视频。下面是我使用的脚本(被上传视频被称为video.mp4):我从Youtube Data API上传的视频在哪里?
const Youtube = require("youtube-api");
const fs = require("fs");
const readJson = require('r-json');
const Lien = require("lien");
const Logger = require("bug-killer");
const opn = require("opn");
const prettyBytes = require("pretty-bytes");
const CREDENTIALS = readJson(`${__dirname}/credentials.json`);
// initialize Lien server
let server = new Lien({
host: "localhost",
port: 3000
});
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]
});
opn(oauth.generateAuthUrl({
access_type: "offline",
scope: ["https://www.googleapis.com/auth/youtube.upload"]
}));
server.addPage("/response", lien => {
Logger.log("Trying to get the token using the following code: " + lien.query.code);
oauth.getToken(lien.query.code, (err, tokens) =>{
if (err){
lien.lien(err, 400);
return Logger.log(err);
}
Logger.log("Got the tokens");
oauth.setCredentials(tokens);
lien.end("The video is being uploaded.");
var req = Youtube.videos.insert({
resource:{
snippet:{
title: "Testing Youtube API",
description: "testing the youtubes"
},
status: {privacyStatus: "private"}
},
part: "snippet, status",
media: {
body: fs.createReadStream("video.mp4")
}
},(err, data) => {
console.log("Done." + data);
process.exit();
});
setInterval(function(){
Logger.log(`${prettyBytes(req.req.connection._bytesDispatched)} bytes uploaded.`);
}, 250);
});
});
我打通的console.log告诉我视频的正确的输出已经上传:
info Trying to get the token using the following code: XXXXXXXXXX
info Got the tokens
info 263 kB bytes uploaded.
info 384 kB bytes uploaded.
info 384 kB bytes uploaded.
info 384 kB bytes uploaded.
Done.
但登录到我的YouTube帐户后,我没有在那里看到视频!我有两个项目设置在我的Google控制板上:
@JaromandaX我认为这是一个合法的问题,我相信其他人也会遇到类似的问题,尤其是考虑到我链接的代码是 - 据我所知 - 唯一示例代码演示视频上传通过node.js的'youtube-api'软件包加入Youtube。请检查我的答案,以解决此问题。 –
我知道这是一个合法的问题(如果我不这么认为的话,我已经将其标记为关闭) - 第一部分是一个笑话,第二部分是我的一个诚实的意见 –
@JaromandaX明白了。花了一晚上来重复上传相同的玩具机器人视频之后,稍微有些胡思乱想...... –