I'm following a tutorial on uploading Youtube videos using Node.Js (here is the link), and it works great. The only problem is, after finishing the script, I can't find my uploaded video. Here is the script I am using (the video being uploaded is called video.mp4):
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);
});
});
I get the correct output through console.log telling me the video has been uploaded:
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.
but after signing into my youtube account, I don't see the video there! I have two projects set up on my Google dashboard: