먼저 다른 제목을 모두 보았습니다. 모두 오래된 것입니다. 내 말은, 그들은 오래된 api를 사용하고 있다는 것이다.Youtube 비디오에서 모든 댓글을 얻는 방법
나는 nextPageToken
<?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 < 5; $i++) {
$str = file_get_contents("https://www.googleapis.com/youtube/v3/commentThreads?key=" . "$ytkey" . "&textFormat=plainText&part=snippet&videoId=" . "$url" . "&maxResults=100&nextPagetoken=" . "$nextPage");
$json = json_decode($str, true); // decode the JSON into an associative array
//echo '<pre>' . print_r($json, true) . '</pre>'; // Print json data as array structer ..
echo "$i - " . "Next Page Token : " . $json['nextPageToken']; // Take the next Page Token for get next 100 comment...
echo "<hr>"; // 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 "<span style='color:red';>" . "$author" . "</span>" . " --> " . "$comment"; // Author and comment
echo "<hr>"; // Divider
}
}
echo "Process over. ";
?>
내가 JSON 어떻게 유래에서 PHP에 그들을 표시하는 방법을 분석하는 방법은 자신의 모든 의견을 표시하는 코드를 작성합니다.
이제는 nextPageTokens를 복용해도 문제가 없습니다. 그러나 나는 의견을 얻을 수 없다.
스크립트를 실행할 때 다른 nextPageToken
을 반환하지만 의견은 같고 첫 페이지에서 왔습니다.
충분한 주석 줄을 추가하려고합니다. 죄송합니다. PHP 코드를 색칠 할 수 없습니다.
사용이 아닌 수동으로하고있는 어떤 이유 구글 PHP 클라이언트 라이브러리? https://github.com/google/google-api-php-client – DaImTo
답변을 연장 할 수 있습니까? – user5481342
지금 바로이 코드를 모두 코딩하고 있습니다. 이 모든 작업을 Google for PHP에서 작성한 라이브러리가 있습니다. 스스로 힘들어지면 기능이 내 요청을 충족시킬 수없는 https://developers.google.com/youtube/v3/code_samples/php#create_and_manage_comments – DaImTo