Search code examples
google-apigoogle-api-php-clientgoogle-apis-exploreryoutube-livestreaming-api

YouTube Live Streaming API Snippet.scheduledStartTime not Working while Creating Live Broadcast


I am creating YouTube live broadcast using API explorer everything is working fine but Snippet.scheduledStartTime is not working fine.

My time zone is +05:00 and country is Pakistan.

I want to schedule event at 2019-01-18 04:50 PM. I have set the Snippet.scheduledStartTime to 2019-01-18T11:50:00.000Z but on event page it shows Starts January 18, 2019 at 3:50 AM (PST) when I click edit it shows wrong country and time zone like that United States (GMT -08:00) Pacific

I want to use javascript or php client libraries.

Please let me know how I can fix it?

Here is my php code

$broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
$broadcastSnippet->setTitle('New Test Broadcast');
$broadcastSnippet->setScheduledStartTime('2019-01-18T11:50:00.000Z');

Solution

  • According to the YouTube Live Streaming API Docs, the format for scheduledStartTime must be in ISO 8601 format:

    datetime

    The date and time that the broadcast is scheduled to start. The value is specified in ISO 8601 (YYYY-MM-DDThh:mm:ss.sZ) format.

    I would suggest that you check the time zone designator you have set.

    Create date with timezone

    I am not a PHP dev but the smartest thing to do IMO would be to create a date in the correct timezone and then out put it in the correct format. After about five minutes of googleing i found this.

    $tz = 'Europe/London';
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
    $dt->setTimestamp($timestamp); //adjust the object to correct timestamp
    echo $dt->format('c');