title: How to get all comments from a Youtube video
body: <p>Firstly, I looked all of other title. All of them out of date. I mean, they are use old api.</p>
  
  <p>I write a code to list all comments with their <code>nextPageToken</code></p>
  
  <hr>
  
  <pre><code>&lt;?php
  $url      = "SE0wDh_pILk"; // Youtube video ID
  $ytkey    = "IzaSyCaRXmJ9XDC4XucAZCzXx7hisCtYEH0mNs"; //"IzaSyBuu-rnbmPAj1DjR6WmyxGmpmQKz8aTXbw"  Your api key
  $nextPage = ""; // Next Page Token for get comments of next Page.
  //$i =0; // DO NOT CHANGE
  
  
  for ($i = 0; $i &lt; 5; $i++) {
      $str = file_get_contents("https://www.googleapis.com/youtube/v3/commentThreads?key=" . "$ytkey" . "&amp;textFormat=plainText&amp;part=snippet&amp;videoId=" . "$url" . "&amp;maxResults=100&amp;nextPagetoken=" . "$nextPage");
  
      $json = json_decode($str, true); // decode the JSON into an associative array
      //echo '&lt;pre&gt;' . print_r($json, true) . '&lt;/pre&gt;'; // Print json data as array structer ..
  
      echo "$i - " . "Next Page Token : " . $json['nextPageToken']; // Take the next Page Token for get next 100 comment...
      echo "&lt;hr&gt;"; // Divider
  
  
      $nextPage = $json['nextPageToken']; // Take token for next query
      // print comments.
  
      foreach ($json['items'] as $val) { // Loop for list comments...
          $author  = $val['snippet']['topLevelComment']['snippet']['authorDisplayName']; //Get Comment Author Name.
          //$author_url = $val['snippet']['topLevelComment']['snippet']['authorChannelUrl']; //Get Comment Author URL.
          //$author_thumbnail_url = $val['snippet']['topLevelComment']['snippet']['authorProfileImageUrl']; //Get Comment Author Thumbnail URL.
          $comment = $val['snippet']['topLevelComment']['snippet']['textDisplay']; //Get Comment Content.
  
          echo "&lt;span style='color:red';&gt;" . "$author" . "&lt;/span&gt;" . " --&gt; " . "$comment"; // Author and comment
          echo "&lt;hr&gt;"; // Divider
      }
  
  }
  
  echo "Process over. ";
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>I learn how to parse json and how to show them on php from stackoverflow. </p>
  
  <p>Now, there is no problem with taking nextPageTokens. But I can't get comments.</p>
  
  <p>When I run the script, It returns different <code>nextPageToken</code> but comments are same, they come from the first page. </p>
  
  <p>I try to add enough comment line.
  Sorry I can't color the php codes.</p>