I'm using the npm package youtube-video-api for uploading a video to one of my you tube channels. pplication is a node web server.
I have generated OAuth credentials after enable You Tube Data Api through google cloud console.
Following is my code, and you can see that I'm authenticating before uploading the video.
var youtube = Youtube({
video: {
part: 'status,snippet'
},
email: '<my-email>',
password: '<my-password>'
});
youtube.authenticate('<my-client-id>',
'<my-client-secret>', function (err, tokens) {
if (err) {
console.error('Cannot authenticate:', err);
return res.status(422).send("An Error occured in video upload");
}
console.log('Session Authenticated with google API');
var video_params = {
resource: {
snippet: {
title: 'Test',
description: 'Test Video'
},
status: {
privacyStatus: 'private'
}
},
scopes: [
'https://www.googleapis.com/auth/youtube.upload',
'https://www.googleapis.com/auth/youtube'
]
};
youtube.upload('test.mp4', video_params, function (err, video) {
if (err) {
console.error('Cannot upload video:', err);
return res.status(422).send("An Error occured in video upload");
}
console.log('Video was uploaded with ID:', video.id);
return res.send(video.id);
});
});
My authentication call returns success. But in uploading the video it gives the following error.
[1] Cannot upload video: { Error [1] at Request._callback (C:\Users\gayans\Desktop\Flexi\FirstClass\fcl_webapp\node_modules\youtube-video-api\node_modules\googleapis\lib\transporters.js:78:15) [1] at Request.self.callback (C:\Users\gayans\Desktop\Flexi\FirstClass\fcl_webapp\node_modules\youtube-video-api\node_modules\request\request.js:373:22) [1] at emitTwo (events.js:106:13) [1] at Request.emit (events.js:191:7) [1] at Request. (C:\Users\gayans\Desktop\Flexi\FirstClass\fcl_webapp\node_modules\youtube-video-api\node_modules\request\request.js:1318:14) [1] at emitOne (events.js:101:20) [1] at Request.emit (events.js:188:7) [1] at IncomingMessage. (C:\Users\gayans\Desktop\Flexi\FirstClass\fcl_webapp\node_modules\youtube-video-api\node_modules\request\request.js:1266:12) [1] at emitNone (events.js:91:20) [1] at IncomingMessage.emit (events.js:185:7) [1] at endReadableNT (_stream_readable.js:974:12) [1] at _combinedTickCallback (internal/process/next_tick.js:80:11) [1] at process._tickCallback (internal/process/next_tick.js:104:9) code: 401, type: 'unauthorized_client' }
Can somebody figure out what's wrong here.
via lkman
No comments:
Post a Comment