Using the link below, the title
can be easily updated:
https://developers.google.com/youtube/v3/live/docs/liveStreams/update?apix=true
.
I wish to implement the same using the YouTube API in Google Apps Script. The code below works successfully, but rather than updating it creates a new stream.
The difference is the link above did not require scheduledStartTime
. But the API requires it. And when scheduledStartTime
is given, it creates a new broadcast rather than updating the original one. If scheduledStartTime
is assigned 1970-01-01T00:00:00Z
it acts as if scheduledStartTime
is not taken into account.
What value to be assigned so that it updates the default broadcast stream rather than updating one. Or there is there anything else I am missing to complete the update process?
Here is my code:
Logger.log('Starting');
service = getService();
if (service.hasAccess()) {
//Fetch the LiveBroadcast Title and Description Details
var url = "https://www.googleapis.com/youtube/v3/liveBroadcasts?broadcastStatus=upcoming&broadcastType=all";
var parameters = {'headers' : {'Content-Type': 'application/json', 'Authorization': 'Bearer ' + service.getAccessToken()}};
var response = UrlFetchApp.fetch(url,parameters);
var result = JSON.parse(response.getContentText());
//Logger.log(result);
var resource = result.items[0];
//Edit the LiveBroadcast Title and Description Details scheduledStartTime
var title = "as per today";
var description = "new desc check";
var scheduledStartTime ='1970-01-01T00:00:00Z';
var privacyStatus = 'public';
//var privacyStatus = 'unlisted';
//var scheduledStartTime = '2020-10-26T04:08:00Z';
data = {
'id' : 'MDaEvnSioI',
'status' : { 'privacyStatus' : 'public' , 'selfDeclaredMadeForKids' : false},
'snippet' : { 'title' : title , 'description' : description , 'scheduledStartTime' : scheduledStartTime }
};
//Update the LiveBroadcast
Logger.log("--");
var jsondata = JSON.stringify(data);
Logger.log(jsondata);
var options = {
'headers': {
'Authorization': 'Bearer ' + service.getAccessToken()
},
'contentType': 'application/json',
'method' : 'post',
'payload': jsondata,
'muteHttpExceptions':true
};
var response = UrlFetchApp.fetch(url2, options);
Logger.log(response.getContentText());
Logger.log('service has access...!!');