I use NodeJS, I want to insert in my script a function to insert a video to a specific playlist.
I saw a lot on internet, and I know Youtube api requires OAuth to work, and so, some HTML page / callback to get the Token.
Did I miss something or is it impossible to handle this token in script without any user interaction ?
Is there a simple example of how doing this ? I tried this using youtube-api npm :
var express = require('express');
var router = express.Router(),
Youtube = require("youtube-api"),
fs = require('fs'),
router.get('/insert', function(req, res, next) {
Youtube.authenticate({
type: "oauth"
, token: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxZ9F0sVpqEXh"
});
var req = Youtube.videos.insert({
"resource": {
// Video title and description
"snippet": {
"title": "Test",
"description": "Test video upload via YouTube API"
},
"status": {
"privacyStatus": "private"
}
},
"part": "snippet,status,id",
"media": {
"body": fs.createReadStream('./test.mp4')
}
}, function (err, data) {
console.log(err);
// insert to playlist
Youtube.playlistItems.insert({
"resource": {
"snippet": {
"playlistId": "xxxxxxxxxxxxxxxxxxxgvjIu",
"resourceId": {
"kind": "youtube#video",
"videoId": data.id // ???
}
},
"status": {
"privacyStatus": "private"
}
}
}, function (err, data) {
if (err) {
return console.log(err);
}
});
});
res.json();
});
I got error 401 :
message: 'Login Required'
EDIT 1
Good video to start : https://www.youtube.com/watch?v=hfWe1gPCnzc
I got a token now, but don't know how to get no limit no this... Now I changed :
Youtube.authenticate({
type: "oauth"
, token: "token_from_google"
});
And I got the error :
message: 'The request cannot be completed because you have exceeded your quota.' } ],
code: 403, message: 'The request cannot be completed because you have exceeded your quota.
I can't understand it ... ?