如何使用youtube API从主页获取预告片和播放列表


How to get trailer & playlist from home page with youtube API

我必须在频道的主页上获取预告片和播放列表。我尝试使用带有主页参数的活动,但我得到的任何内容都不允许我获取播放列表或预告片。

以下是我的一些相关代码:

  $oYoutubeService = new Google_Service_YouTube($oGoogle);
  $playlists_optParams = array('home' => true);
  $stream = $oYoutubeService->activities->listActivities('snippet', $playlists_optParams);
  var_dump($stream);

但在这个结果中,我没有任何预告片或播放列表。

如果我的目标不明确,例如在频道上youtube.com/user/youtubenation我想获得预告片("妮可·里奇保留...")和之后的播放列表("YouTube Nation Playlist","关于泽弗兰克的真实事实"......

有没有一种简单的方法可以从频道的主页取回预告片、播放列表或视频?

谢谢

我构建了这个混乱的代码片段,它抓取了一个 youtube 频道页面并去除了视频预告片 ID,然后嵌入了视频。这是另一个项目,可以使用一些整理。

<?php
// Fetch YouTube channel page.
//  ------REPLACE THE ADDRESS INSIDE THE QUOTES WITH THE DESIRED YOUTUBE CHANNEL------
$html = file_get_contents('http://www.youtube.com/user/YOUR_YOUTUBE_CHANNEL/');
// Identifies what text we are searching for, then returns the cursor position in the file where that text string begins.
$videoID = 'data-video-id';
$pos = stripos($html, $videoID);
// Remove all of the content before the data-video-id, and remove the new first 15 characters of the file, which would now be-> data-video-id:"
$str2 = substr($html, $pos);
$str3 = substr($str2, 15);
// Grab the first 11 characters, cause YouTube video IDs are 11 characters long.
$id = substr($str3, 0,11);
// Create a string with the youtube video URL, using the ID variable.
$ytlink = 'http://www.youtube.com/v/' . $id;
//Determine whether user is mobile, and if they are, don't size the video.
$isMobile = (bool) strpos($_SERVER['HTTP_USER_AGENT'],'Mobile');
if ($isMobile) {
    $size = " ";
} else {
//These values can be changed to your own needs.
    $size = "width=425 height=350";
}           
// Embed the YouTube video.
echo '<object ' . $size . ' data="' . $ytlink . '"type="application/x-shockwave-flash">';
echo '<param name="src" value="' . $ytlink . '" /></object>';
?>