gpt4 book ai didi

PHP YouTube Api V3 MaxResults 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:26:03 25 4
gpt4 key购买 nike

我刚刚使用 YouTube 服务将 Google Api 实现到我的应用程序中以获取 YouTube 视频。就获得结果而言,它按预期工作,但由于某种原因 MAXRESULTS 不起作用。它会显示结果,但如果我设置例如 15,那么它会在页面上显示无数结果。

    <?php
//Load The Google Api Client
//Added Google Api Support 01/21/2016
set_include_path(get_include_path().PATH_SEPARATOR.'vendor/google/apiclient/src');


//=================================================================================
//START GOOGLE API INTEGRATION
//=================================================================================
$htmlBody = <<<END
<form method="GET">
<div>
Search For YouTube Video<br>
<input type="search" id="q" name="q" placeholder="SEARCH" size="30">
</div>
<input type="submit" value="Search">
</form>
END;

if ( $_GET['q'] )
{
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';


$DEVELOPER_KEY = 'REMOVED FOR OBVIOUS REASONS';

$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);

// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);

try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => 15,
'type' => 'video',
));

$videos = '';

// Add each result to the appropriate list, and then display the lists of
// matching videos.
$i = 0;
foreach ($searchResponse['items'] as $searchResult)
{
switch ($searchResult['id']['kind'])
{
case 'youtube#video':
$videotitle = $searchResult['snippet']['title'];
$videoid = $searchResult['id']['videoId'];

$videoembed = '<iframe width="150" height="150" src="http://www.youtube.com/embed/'.$videoid.'?autoplay=0&hd=1&vq=hd720" frameborder="0" allowfullscreen></iframe>';
$htmloutput .= '
<table width="50%" align="center">
<tr>
<th colspan="2">'.$i.'. '.$videotitle.'</th>
</tr>
<tr>
<td width="40%">'.$videoembed.'</td>
<td width="60%" align="center">
<form action="index.php" method="post" id="conversionForm">
<input type="hidden" name="youtubeURL" value="'.$videoid.'">
<input type="hidden" value="320" name="quality">
<input type="submit" name="submit" value="Create MP3 File">
</form>
</td>
</tr>
</table>
';
$videos .= '<li>'.$htmloutput.'</li>';
break;
}
$i++;
}

$htmlBody .= <<<END
<h3>Videos</h3>
<ul>$videos</ul>
END;
} catch (Google_Service_Exception $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()));
}
}

//=================================================================================
//END GOOGLE API INTEGRATION
//=================================================================================

?>

最佳答案

哇,我一定很累。我想通了。

改变

$html输出.='

$html输出='

这解决了我遇到的问题。

谢谢大家!

关于PHP YouTube Api V3 MaxResults 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34918483/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com