Youtube 数据 api v2 到 v3
Youtube data api v2 to v3
这是我在我的网站上用来显示我的 2 个帐户最近视频的内容。
但是不再工作了,因为 google 更改了 api youtube 数据 api v3.
我不知道如何解决这个问题。我尝试学习新系统,但错误太多。
这段代码不是我写的,是朋友写的。他几个月前去世了。所以我卡住了。
但是我明白了
警告:simplexml_load_file():SSL 操作失败,代码为 1。OpenSSL 错误消息:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate 在
中验证失败
我的页面=spel.stajlplejs.com/test/demo1/blog.php
这就是它的行为方式http://i.imgur.com/BDvBLIE.png
新版本 v3
$youtube_videos = array();
$active = "all";
$channels = array('UUFllMgwJeO047KMkF_y4jow', 'UUWy8jDk2k93E0c6iGdMnt_A');
if (in_array($_GET['channel'], $channels)) {
$channels = array($_GET['channel']);
$active = $_GET['channel'];
}
$today = time();
$timetest = strtotime("-6 months", $today);
foreach ($channels as $channeld) {
$xmlresultsup = simplexml_load_file('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId='.$channeld.'&key=AIzaSyD05SHXPPLNEUaSbWKwKL2Uam0oH0GGq-U');
if ($err || $xmlresultsup->Error) {
$errorMsg = $xmlresultsup->Error->Message;
} else {
foreach($xmlresultsup->channel->item as $item) {
$videotime = strtotime($item->pubDate);
if($timetest < $videotime) {
$youtube_videos[$videotime][] = $item;
}
}
}
}
krsort($youtube_videos);
?>
<div class="blog_top">
<div class="blog_top_menu all<?php if($active == "all"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog"><span>All</span></a></div>
<div class="blog_top_menu channel1<?php if($active == "UUFllMgwJeO047KMkF_y4jow"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog/channel1"><span>Channel1</span></a></div>
<div class="blog_top_menu channel2<?php if($active == "UUWy8jDk2k93E0c6iGdMnt_A"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog/channel2"><span>Channel2</span></a></div>
<div class="float_clear"></div>
</div>
<div class="blog_content">
<?php foreach($youtube_videos as $items):
foreach($items as $item):
$guid = $item->guid;
$pubDate = date("F j, Y", strtotime($item->pubDate));
$title = $item->title;
$link = $item->link;
$author = $item->author;
$media = $item->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
$id = str_replace("http://gdata.youtube.com/feeds/api/videos/","", $guid);
?>
<div class="blog_content_entry">
<a href="<?php echo htmlentities($link, ENT_QUOTES, 'UTF-8'); ?>" target="_blank">
<div class="blog_content_entry_image" style="background-image:url('<?php echo htmlentities($thumbnail, ENT_QUOTES, 'UTF-8'); ?>')"></div>
<div class="blog_content_entry_description">
<div class="blog_content_entry_description_title"><span><?php echo htmlentities("New {$author} Video", ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_content"><span><?php echo htmlentities($title, ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_details">
<div class="blog_content_entry_description_details_link"><span>View Video</span></div>
<div class="blog_content_entry_description_details_date"><span><?php echo $pubDate; ?></span></div>
<div class="float_clear"></div>
</div>
</div>
</a>
</div>
<?php endforeach; endforeach; ?>
<div class="float_clear"></div>
</div>
<?php
?>
老
<?php
$page = "blog";
include_once "header.php";
$youtube_videos = array();
$active = "all";
$channels = array('channel1', 'channel2');
if (in_array($_GET['channel'], $channels)) {
$channels = array($_GET['channel']);
$active = $_GET['channel'];
}
$today = time();
$timetest = strtotime("-6 months", $today);
foreach ($channels as $channeld) {
$xmlresultsup = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/'.$channeld.'/uploads?v=1&alt=rss&max-results=50&blah='.$ran);
if ($err || $xmlresultsup->Error) {
$errorMsg = $xmlresultsup->Error->Message;
} else {
foreach($xmlresultsup->channel->item as $item) {
$videotime = strtotime($item->pubDate);
if($timetest < $videotime) {
$youtube_videos[$videotime][] = $item;
}
}
}
}
krsort($youtube_videos);
?>
<div class="blog_top">
<div class="blog_top_menu all<?php if($active == "all"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog"><span>All</span></a></div>
<div class="blog_top_menu channel1<?php if($active == "channel1"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog/channel1"><span>GayGod</span></a></div>
<div class="blog_top_menu channel2<?php if($active == "channel2"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog/channel2"><span>Lush</span></a></div>
<div class="float_clear"></div>
</div>
<div class="blog_content">
<?php foreach($youtube_videos as $items):
foreach($items as $item):
$guid = $item->guid;
$pubDate = date("F j, Y", strtotime($item->pubDate));
$title = $item->title;
$link = $item->link;
$author = $item->author;
$media = $item->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
$id = str_replace("http://gdata.youtube.com/feeds/api/videos/","", $guid);
?>
<div class="blog_content_entry">
<a href="<?php echo htmlentities($link, ENT_QUOTES, 'UTF-8'); ?>" target="_blank">
<div class="blog_content_entry_image" style="background-image:url('<?php echo htmlentities($thumbnail, ENT_QUOTES, 'UTF-8'); ?>')"></div>
<div class="blog_content_entry_description">
<div class="blog_content_entry_description_title"><span><?php echo htmlentities("New {$author} Video", ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_content"><span><?php echo htmlentities($title, ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_details">
<div class="blog_content_entry_description_details_link"><span>View Video</span></div>
<div class="blog_content_entry_description_details_date"><span><?php echo $pubDate; ?></span></div>
<div class="float_clear"></div>
</div>
</div>
</a>
</div>
<?php endforeach; endforeach; ?>
<div class="float_clear"></div>
</div>
<?php
include_once "footer.php";
?>
用于转换 Youtube 数据Api V2 到 V3
Youtube 在 2014 年弃用了 V2 Libaray
只需更改您的 Link
替换为
您可以生成 Link 用于获取播放列表、视频等....数据检查以下 Link
https://developers.google.com/youtube/v3/docs/
此处PHP的示例代码
这是我在我的网站上用来显示我的 2 个帐户最近视频的内容。 但是不再工作了,因为 google 更改了 api youtube 数据 api v3.
我不知道如何解决这个问题。我尝试学习新系统,但错误太多。
这段代码不是我写的,是朋友写的。他几个月前去世了。所以我卡住了。
但是我明白了 警告:simplexml_load_file():SSL 操作失败,代码为 1。OpenSSL 错误消息:error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate 在
中验证失败我的页面=spel.stajlplejs.com/test/demo1/blog.php
这就是它的行为方式http://i.imgur.com/BDvBLIE.png
新版本 v3
$youtube_videos = array();
$active = "all";
$channels = array('UUFllMgwJeO047KMkF_y4jow', 'UUWy8jDk2k93E0c6iGdMnt_A');
if (in_array($_GET['channel'], $channels)) {
$channels = array($_GET['channel']);
$active = $_GET['channel'];
}
$today = time();
$timetest = strtotime("-6 months", $today);
foreach ($channels as $channeld) {
$xmlresultsup = simplexml_load_file('https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId='.$channeld.'&key=AIzaSyD05SHXPPLNEUaSbWKwKL2Uam0oH0GGq-U');
if ($err || $xmlresultsup->Error) {
$errorMsg = $xmlresultsup->Error->Message;
} else {
foreach($xmlresultsup->channel->item as $item) {
$videotime = strtotime($item->pubDate);
if($timetest < $videotime) {
$youtube_videos[$videotime][] = $item;
}
}
}
}
krsort($youtube_videos);
?>
<div class="blog_top">
<div class="blog_top_menu all<?php if($active == "all"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog"><span>All</span></a></div>
<div class="blog_top_menu channel1<?php if($active == "UUFllMgwJeO047KMkF_y4jow"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog/channel1"><span>Channel1</span></a></div>
<div class="blog_top_menu channel2<?php if($active == "UUWy8jDk2k93E0c6iGdMnt_A"): ?> active<?php endif; ?>"><a href="http://www.matthewlush.com/blog/channel2"><span>Channel2</span></a></div>
<div class="float_clear"></div>
</div>
<div class="blog_content">
<?php foreach($youtube_videos as $items):
foreach($items as $item):
$guid = $item->guid;
$pubDate = date("F j, Y", strtotime($item->pubDate));
$title = $item->title;
$link = $item->link;
$author = $item->author;
$media = $item->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
$id = str_replace("http://gdata.youtube.com/feeds/api/videos/","", $guid);
?>
<div class="blog_content_entry">
<a href="<?php echo htmlentities($link, ENT_QUOTES, 'UTF-8'); ?>" target="_blank">
<div class="blog_content_entry_image" style="background-image:url('<?php echo htmlentities($thumbnail, ENT_QUOTES, 'UTF-8'); ?>')"></div>
<div class="blog_content_entry_description">
<div class="blog_content_entry_description_title"><span><?php echo htmlentities("New {$author} Video", ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_content"><span><?php echo htmlentities($title, ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_details">
<div class="blog_content_entry_description_details_link"><span>View Video</span></div>
<div class="blog_content_entry_description_details_date"><span><?php echo $pubDate; ?></span></div>
<div class="float_clear"></div>
</div>
</div>
</a>
</div>
<?php endforeach; endforeach; ?>
<div class="float_clear"></div>
</div>
<?php
?>
老
<?php
$page = "blog";
include_once "header.php";
$youtube_videos = array();
$active = "all";
$channels = array('channel1', 'channel2');
if (in_array($_GET['channel'], $channels)) {
$channels = array($_GET['channel']);
$active = $_GET['channel'];
}
$today = time();
$timetest = strtotime("-6 months", $today);
foreach ($channels as $channeld) {
$xmlresultsup = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/'.$channeld.'/uploads?v=1&alt=rss&max-results=50&blah='.$ran);
if ($err || $xmlresultsup->Error) {
$errorMsg = $xmlresultsup->Error->Message;
} else {
foreach($xmlresultsup->channel->item as $item) {
$videotime = strtotime($item->pubDate);
if($timetest < $videotime) {
$youtube_videos[$videotime][] = $item;
}
}
}
}
krsort($youtube_videos);
?>
<div class="blog_top">
<div class="blog_top_menu all<?php if($active == "all"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog"><span>All</span></a></div>
<div class="blog_top_menu channel1<?php if($active == "channel1"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog/channel1"><span>GayGod</span></a></div>
<div class="blog_top_menu channel2<?php if($active == "channel2"): ?> active<?php endif; ?>"><a href="http://www.website.com/blog/channel2"><span>Lush</span></a></div>
<div class="float_clear"></div>
</div>
<div class="blog_content">
<?php foreach($youtube_videos as $items):
foreach($items as $item):
$guid = $item->guid;
$pubDate = date("F j, Y", strtotime($item->pubDate));
$title = $item->title;
$link = $item->link;
$author = $item->author;
$media = $item->children('http://search.yahoo.com/mrss/');
$attrs = $media->group->thumbnail[0]->attributes();
$thumbnail = $attrs['url'];
$id = str_replace("http://gdata.youtube.com/feeds/api/videos/","", $guid);
?>
<div class="blog_content_entry">
<a href="<?php echo htmlentities($link, ENT_QUOTES, 'UTF-8'); ?>" target="_blank">
<div class="blog_content_entry_image" style="background-image:url('<?php echo htmlentities($thumbnail, ENT_QUOTES, 'UTF-8'); ?>')"></div>
<div class="blog_content_entry_description">
<div class="blog_content_entry_description_title"><span><?php echo htmlentities("New {$author} Video", ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_content"><span><?php echo htmlentities($title, ENT_QUOTES, 'UTF-8'); ?></span></div>
<div class="blog_content_entry_description_details">
<div class="blog_content_entry_description_details_link"><span>View Video</span></div>
<div class="blog_content_entry_description_details_date"><span><?php echo $pubDate; ?></span></div>
<div class="float_clear"></div>
</div>
</div>
</a>
</div>
<?php endforeach; endforeach; ?>
<div class="float_clear"></div>
</div>
<?php
include_once "footer.php";
?>
用于转换 Youtube 数据Api V2 到 V3
Youtube 在 2014 年弃用了 V2 Libaray
只需更改您的 Link
替换为
您可以生成 Link 用于获取播放列表、视频等....数据检查以下 Link
https://developers.google.com/youtube/v3/docs/
此处PHP的示例代码