【发布时间】:2015-06-29 15:45:13
【问题描述】:
我在使用 youtube api 时遇到了一些问题。我想从单个视频中检索信息。
我已经得到了什么:
我可以从指定的播放列表中获取视频及其所有信息(如标题、描述等)
我从 Url 获取 id 播放列表:
$playlist = $_GET['pl'];
然后我从播放列表中获取视频信息:
$response = $youtube->playlistItems->listPlaylistItems('id,snippet,contentDetails', ['playlistId' => $playlist, 'maxResults' => '10']);
然后我可以很容易地从这些视频中获取和显示信息,这要归功于 foreach:
foreach($response['items'] as $video){
echo $video['contentDetails']['videoId'];
echo $video['snippet']['title'];
echo substr($video['snippet']['description'], 0, 430);}
我想要什么:
现在我只是把 videoId 放到一个链接中:
href="index.php?requ=video&v=<?= $video['contentDetails']['videoId']; ?>&pl=<?= $playlist ?>"
这样我可以将 videoId 放入我嵌入视频的其他页面:
$vid = $_GET['v'];
<iframe height ="432" width="760" src="https://www.youtube.com/embed/<?= $vid; ?>"></iframe>
但是问题来了,当我尝试这样时,我无法从该视频中获取任何信息:
$viewing = $youtube->videos->listVideos("snippet", ['id' => $vid]);
echo $viewing['snippet']['title'];
它返回 NULL
如果有人能帮帮我,那就太棒了
【问题讨论】: