title: Fetching YouTube Live Stream Chat messages
body: <p>Since this is a question about the new YouTube API that has just been released it is not a duplicate.</p>
  
  <p>I am trying to fetch the chat messages from the YouTube API 3. I have tried everything I can and I am stuck.</p>
  
  <p>I need the liveChatId to be able to fetch them but I don't know how to retrieve that value. The API says that you get it from liveBroadcast snippet.liveChatId, but with the code I've attached in this post there is no value in the liveChatId field. It is just empty. How do I properly retrieve the liveChatId?</p>
  
  <pre><code>&lt;?php
  session_start();
  
  // Call set_include_path() as needed to point to your client library.
  require_once 'Google/autoload.php';
  require_once 'Google/Client.php';
  require_once 'Google/Service/YouTube.php';
  
  $OAUTH2_CLIENT_ID = 'MY-CLIENT-ID';
  $OAUTH2_CLIENT_SECRET = 'MY-CLIENT-SECRET';
  
  $client = new Google_Client();
  $client-&gt;setClientId($OAUTH2_CLIENT_ID);
  $client-&gt;setClientSecret($OAUTH2_CLIENT_SECRET);
  $client-&gt;setScopes('https://www.googleapis.com/auth/youtube');
  $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'],
      FILTER_SANITIZE_URL);
  
  $client-&gt;setRedirectUri($redirect);
  
  
  // Define an object that will be used to make all API requests.
  $youtube = new Google_Service_YouTube($client);
  $_SESSION['state'] = $_GET['state'];
  if (isset($_GET['code'])) {
    if (strval($_SESSION['state']) !== strval($_GET['state'])) {
      die('The session state did not match.');
    }
  
    $client-&gt;authenticate($_GET['code']);
    $_SESSION['token'] = $client-&gt;getAccessToken();
    header('Location: ' . $redirect);
  }
  
  if (isset($_SESSION['token'])) {
    $client-&gt;setAccessToken($_SESSION['token']);
  }
  
  // Check to ensure that the access token was successfully acquired.
  if ($client-&gt;getAccessToken()) {
    try {
      // Execute an API request that lists broadcasts owned by the user who
      // authorized the request.
      $broadcastsResponse = $youtube-&gt;liveBroadcasts-&gt;listLiveBroadcasts(
          'id,snippet',
          array(
              'mine' =&gt; 'true',
          ));
  
  var_dump($broadcastsResponse['items']);
  
      $htmlBody .= "&lt;h3&gt;Live Broadcasts&lt;/h3&gt;&lt;ul&gt;";
      foreach ($broadcastsResponse['items'] as $broadcastItem) {
        $htmlBody .= $broadcastItem['snippet']['title'] ."&lt;br /&gt;Chat ID: ". $broadcastItem['liveChatId'] ."&lt;br /&gt;ID: ". $broadcastItem['id'];
      }
      $htmlBody .= '&lt;/ul&gt;';
  
    } catch (Google_Service_Exception $e) {
      $htmlBody .= sprintf('&lt;p&gt;A service error occurred: &lt;code&gt;%s&lt;/code&gt;&lt;/p&gt;',
          htmlspecialchars($e-&gt;getMessage()));
    } catch (Google_Exception $e) {
      $htmlBody .= sprintf('&lt;p&gt;An client error occurred: &lt;code&gt;%s&lt;/code&gt;&lt;/p&gt;',
          htmlspecialchars($e-&gt;getMessage()));
    }
  
    $_SESSION['token'] = $client-&gt;getAccessToken();
  } else {
    // If the user hasn't authorized the app, initiate the OAuth flow
    $state = mt_rand();
    $client-&gt;setState($state);
    $_SESSION['state'] = $state;
  
    $authUrl = $client-&gt;createAuthUrl();
    $htmlBody = &lt;&lt;&lt;END
    &lt;h3&gt;Authorization Required&lt;/h3&gt;
    &lt;p&gt;You need to &lt;a href="$authUrl"&gt;authorize access&lt;/a&gt; before proceeding.&lt;p&gt;
  END;
  }
  ?&gt;
  
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;My Live Streams&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;?=$htmlBody?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Where am I lost?</p>