我有一个网站与电影床单,我想显示电影的预告片。为了做到这一点,是否有可能从YouTube搜索中获取顶级YouTube视频的URL?
因为输入“电影名称预告片”大部分时间都很好,而且预告片通常是最高的视频,所以很容易。
在另一个主题上,如果选择的视频不正确,允许用户修改视频的最佳方法是什么?与投票制度,所以它将需要至少4-5票,以改变视频。
发布于 2013-09-08 00:45:55
这是一个youtube搜索,我在我的一个老站点上使用了google的youtube api。
<?php
// Call set_include_path() as needed to point to your client library.
require_once ('video/Google_Client.php');
require_once ('video/Google_YouTubeService.php');
/* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
Google APIs Console <http://code.google.com/apis/console#access>
Please ensure that you have enabled the YouTube Data API for your project. */
$DEVELOPER_KEY = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);
$youtube = new Google_YoutubeService($client);
try {
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_POST['query'],
'maxResults' => '48',
));
$videos = '';
$channels = '';
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= $searchResult;
break;
}
}
} 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()));
}
echo print_r($videos);
?>我使用了一个表单来发布搜索查询(注意$_ post ' search‘变量,它将是要搜索的字符串,在您的例子中是电影名称)
https://stackoverflow.com/questions/18679004
复制相似问题