/**
  * @param LiveBroadcast $liveBroadcast
  * @param string        $privacyStatus
  * @param string|null   $id
  * @return \Google_Service_YouTube_LiveBroadcast
  */
 protected function setupBroadcast(LiveBroadcast $liveBroadcast, $privacyStatus = 'public', $id = null)
 {
     $title = $liveBroadcast->getName();
     $description = $liveBroadcast->getDescription();
     $start = $liveBroadcast->getStartTimestamp();
     $end = $liveBroadcast->getEndTimestamp();
     if (new \DateTime() > $start) {
         $start = new \DateTime();
         $start->add(new \DateInterval('PT1S'));
     }
     $broadcastSnippet = new \Google_Service_YouTube_LiveBroadcastSnippet();
     $broadcastSnippet->setTitle($title);
     $broadcastSnippet->setDescription($description);
     $broadcastSnippet->setScheduledStartTime($start->format(\DateTime::ATOM));
     $broadcastSnippet->setScheduledEndTime($end->format(\DateTime::ATOM));
     $status = new \Google_Service_YouTube_LiveBroadcastStatus();
     $status->setPrivacyStatus($privacyStatus);
     $broadcastInsert = new \Google_Service_YouTube_LiveBroadcast();
     if ($id !== null) {
         $broadcastInsert->setId($id);
     }
     $broadcastInsert->setSnippet($broadcastSnippet);
     $broadcastInsert->setStatus($status);
     $broadcastInsert->setKind('youtube#liveBroadcast');
     return $broadcastInsert;
 }
    if (strval($_SESSION['state']) !== strval($_GET['state'])) {
        die('The session state did not match.');
    }
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();
    header('Location: ' . $redirect);
}
if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
}
// Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
    try {
        // Create an object for the liveBroadcast resource's snippet. Specify values
        // for the snippet's title, scheduled start time, and scheduled end time.
        $broadcastSnippet = new Google_Service_YouTube_LiveBroadcastSnippet();
        $broadcastSnippet->setTitle('New Broadcast');
        $broadcastSnippet->setScheduledStartTime('2034-01-30T00:00:00.000Z');
        $broadcastSnippet->setScheduledEndTime('2034-01-31T00:00:00.000Z');
        // Create an object for the liveBroadcast resource's status, and set the
        // broadcast's status to "private".
        $status = new Google_Service_YouTube_LiveBroadcastStatus();
        $status->setPrivacyStatus('private');
        // Create the API request that inserts the liveBroadcast resource.
        $broadcastInsert = new Google_Service_YouTube_LiveBroadcast();
        $broadcastInsert->setSnippet($broadcastSnippet);
        $broadcastInsert->setStatus($status);
        $broadcastInsert->setKind('youtube#liveBroadcast');
        // Execute the request and return an object that contains information
        // about the new broadcast.
        $broadcastsResponse = $youtube->liveBroadcasts->insert('snippet,status', $broadcastInsert, array());