Php youtube api maxResults

Php youtube api maxResults,php,html,youtube,youtube-api,Php,Html,Youtube,Youtube Api,我试图寻找类似的东西,但没有找到任何相关的。 我的问题是,当你搜索一个视频时,它第一次只显示8个视频,然后每次单击“更多视频”,它会再添加8个视频。 我猜我在“maxResults”或/和“pageToken”上做错了什么。 如果我正确理解版本3中的API,您只能显示50个视频,然后您需要转到另一个页面,是否有办法使其向下继续? 感谢您的帮助 <?php $htmlBody = ""; // This code will execute if the user entered a sea

我试图寻找类似的东西,但没有找到任何相关的。 我的问题是,当你搜索一个视频时,它第一次只显示8个视频,然后每次单击“更多视频”,它会再添加8个视频。 我猜我在“maxResults”或/和“pageToken”上做错了什么。 如果我正确理解版本3中的API,您只能显示50个视频,然后您需要转到另一个页面,是否有办法使其向下继续? 感谢您的帮助

<?php
$htmlBody = "";

// This code will execute if the user entered a search query in the form
// and submitted the form. Otherwise, the page displays the form above.
$index_playlist = '<iframe width="300" height="180" src="//www.youtube.com/embed/videoseries?list=PLn1aPDOSlmD8vLeP8S2KDogDcmCgtTmHg" frameborder="0" allowfullscreen></iframe>';
if ($_GET['q']) {
$index_playlist = '';

// Call set_include_path() as needed to point to your client library.

require_once 'google_analytics/src/Google_Client.php';
require_once 'google_analytics/src/contrib/Google_YouTubeService.php';

/*
* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
* Google Cloud Console <https://cloud.google.com/console>
* Please ensure that you have enabled the YouTube Data API for your project.
*/
$DEVELOPER_KEY = 'HIDDEN_FOR_THIS_POST';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
// Define an object that will be used to make all API requests.
$youtube = new Google_YouTubeService($client);
    $result = 8;
    $results = $results + $result;
    try {
    // Call the search.list method to retrieve results matching the specified
    // query term.
    if ($_GET['more']) {
        $searchResponse = $youtube->search->listSearch('id,snippet', array(
          'q' => $_GET['q'],
          'pageToken' => $_GET['CAgQAA'],
          'maxResults' => $result,
          'type' => 'video',
          ));
    } else {
        $searchResponse = $youtube->search->listSearch('id,snippet', array(
          'q' => $_GET['q'],
          'maxResults' => $results,
          'type' => 'video',
        ));
    };

//echo $searchResponse['nextPageToken'];
//exit;

    $videos = '';
    $channels = '';
    $playlists = '';

    // Add each result to the appropriate list, and then display the lists of
    // matching videos, channels, and playlists.
    foreach ($searchResponse['items'] as $searchResult) {
      switch ($searchResult['id']['kind']) {
        case 'youtube#video':
            $htmlBody .= '<iframe width="300" height="180" src="//www.youtube.com/embed/' . $searchResult['id']['videoId'] . '" frameborder="0" allowfullscreen style="margin-right:30px; margin-bottom:30px"></iframe>';
//          $videos .= sprintf('<li>%s</li>',
//          $videos .= sprintf('<li><a href="%s"</a></li>',
//              $searchResult['snippet']['title'], $searchResult['id']['videoId']);
          break;
/*      case 'youtube#channel':
          $channels .= sprintf('<li>%s (%s)</li>',
            $searchResult['snippet']['title'], $searchResult['id']['channelId']);
          break;
        case 'youtube#playlist':
          $playlists .= sprintf('<li>%s (%s)</li>',
              $searchResult['snippet']['title'], $searchResult['id']['playlistId']);
          break;
*/
        };
    };
//  <ul>$videos</ul>
//  <a href="<ul>$videos</ul>"<a/>
/*    $htmlBody .= <<<END
    <h3>Videos</h3>
    <a href="<ul>$videos</ul>"</a>
    <a href="<ul>$playlists</ul>"</a>

END; */

    } catch (Google_ServiceException $e) {
        $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
        htmlspecialchars($e->getMessage()));
    } catch (Google_Exception $e) {
        $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
        htmlspecialchars($e->getMessage()));
    };
};
?>

<!doctype html>
<html>
  <head>
    <title>TubeSearch</title>
  </head>
  <body>

  <form method="GET">
      <div>
        TubeSearch:
        <br>
            <input type="search" id="q" name="q" placeholder="Enter Search Term">
        </br>
      </div>
      <input type="submit" value="Search">
    </form>
    <?php if (isset($_GET['q'])) : ?>
    <form method="GET">
    <input type="hidden" name="q" value="<?php echo $_GET['q']; ?>">
    <input type="hidden" name="more" value="<?php echo $_GET['q']; ?>">
    <input type="submit" name="more" value="More Videos">
    </form>
    <?php endif; ?>

    <?=$htmlBody?>
    <?=$index_playlist?>

  </body>
</html>

是的,
CAqQAA
是从Youtube返回的字符串。您正在将它放入
$\u GET
数组中,在那里它找不到它。对于
页面令牌
,您必须使用
$searchResponse['nextPageToken']


您可以将其作为
隐藏的
放入表单中,那么您得到了多少结果?你对
maxResult
pageToken
的想法应该行得通。我得到了8个结果,但只有8个,无论我按“搜索”还是“更多视频”
$\u GET['caqaa']
的确切来源是哪里?如果你看下面带有$searchResponse的if语句,你会看到
echo$searchResponse['nextPageToken'它将输出
CAqQAA
好的,我添加了我的下一个评论作为回答..谢谢,但现在它只显示前8个视频,然后如果你按“更多视频”,它会显示我不知道什么,我想会对前10个视频加扰是的,你仍然必须添加
maxResults