Reputation: 7460
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:
Upvotes: 2
Views: 585
Reputation: 7460
Hope this can help the next developers building Youtube Data API connections using Node.js save a few hours... assuming you're also a Youtube newbie like me.
This frustrated me for a while but ultimately some of the videos started popping up on my YouTube dashboard for my channel. The video I has used was a sample video that I downloaded from this website, and that was part of the problem. Every time I was uploading the video, it was promptly removed for violating terms of service, likely for copyright or credential reasons.
However, you can see if the actual implementation did work by clicking your Video Manager. The videos themselves never made it to my list of uploaded videos, but they did show up within the Video Manager view: .
This post also describes a similar issue.
So a few rules of thumb: (1) find your own videos and tag appropriately with details to avoid the upload being removed for terms of service (2) check your Video Manager for a more detailed view of your video uploads that simply the "Uploads" tab.
Edit: the author of the article also responded to my comment and offered a good suggestion to look in my Creator Studio.
Upvotes: 3