【发布时间】:2015-12-06 02:29:22
【问题描述】:
这是我在我的网站上用来显示我的 2 个帐户最近的视频的内容。 但是因为谷歌改变了 api youtube data api v3,所以不再工作了。
我不知道如何解决这个问题。我尝试学习新系统,但错误太多。
这段代码不是我写的,是朋友写的。他在几个月前去世了。所以我卡住了。
但我明白了 警告:simplexml_load_file():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14090086:SSL 例程:SSL3_GET_SERVER_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";
?>
【问题讨论】:
标签: php api youtube-api youtube-data-api