I'm trying to broadcast a event on YouTube using googleapi but it throwing me an response with an error saying login required.
I already have enabled the YouTube api in my developer console.
and here is my code..
const { google } = require('googleapis');
var OAuth2 = google.OAuth2;
const { OAuth2Client } = require('google-auth-library');
const auth = new OAuth2Client(
'CLIENT_ID', //CLIENT_ID
'CLIENT_SECRET', //MY_CLIENT_SECRET,
'http://localhost:8000/'//YOUR_REDIRECT_URL
);
OAuth2Client.Credentials = {
access_token: "access_token", // of client
refresh_token: "refresh_token" // of client
};
const youtube = google.youtube({
version: 'v3',
auth: OAuth2Client
});
broadcastParams = {
"auth": OAuth2Client,
"part": "snippet,status,contentDetails",
"resource": {
"snippet": {
"title": "Tesing NodeJS 123",
"scheduledStartTime": "2018-03-03T18:02:00.000Z",
"scheduledEndTime": "2018-03-03T18:05:00.000Z",
},
"status": {
"privacyStatus": "private",
},
"contentDetails": {
"monitorStream": {
"enableMonitorStream": true,
}
}
}
};
youtube.liveBroadcasts.insert(broadcastParams, function (err, broadcast) {
if (err) {
return console.log('Error creating broadcast: ', err);
}
console.log('Broadcast = ' + JSON.stringify(broadcast));
});
here is the error response it returned ,
errors:
[ { domain: 'global',
reason: 'required',
message: 'Login Required',
locationType: 'header',
location: 'Authorization' } ] }
i refered to this Error: "message": "Login Required" when use Youtube Analytics API and "Login Required" error when trying to create live broadcast using YoutubeV3 API but still it wasn't any help.
any guesses?