【问题标题】:Youtube data api v2 to v3Youtube 数据 api v2 到 v3
【发布时间】:2015-12-06 02:29:22
【问题描述】:

这是我在我的网站上用来显示我的 2 个帐户最近的视频的内容。 但是因为谷歌改变了 api youtube data api v3,所以不再工作了。

我不知道如何解决这个问题。我尝试学习新系统,但错误太多。

这段代码不是我写的,是朋友写的。他在几个月前去世了。所以我卡住了。

我使用v3的地方,链接应该是https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&maxResults=50&playlistId=UUFllMgwJeO047KMkF_y4jow&key=AIzaSyD05SHXPPLNEUaSbWKwKL2Uam0oH0GGq-U

但我明白了 警告: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


    【解决方案1】:

    用于将 Youtube Data Api V2 转换为 V3

    Youtube 在 2014 年弃用 V2 Libaray

    只需更改您的链接

    http://gdata.youtube.com/feeds/api/users/'.$channeld.'/uploads?v=1&alt=rss&max-results=50&blah='.$ran

    替换为

    https://www.googleapis.com/youtube/v3/search?key="Api Key "&channelId="Channel ID"&part=snippet,id&order=date&maxResults=20

    您可以生成用于获取播放列表、视频等的链接......数据检查以下链接

    https://developers.google.com/youtube/v3/docs/

    这里是 PHP 的示例代码

    https://developers.google.com/youtube/v3/code_samples/php

    【讨论】:

      猜你喜欢
      • 2015-07-06
      • 2012-12-22
      • 2021-12-25
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 2015-09-27
      • 2016-06-26
      • 1970-01-01
      相关资源
      最近更新 更多