gpt4 book ai didi

php - 使用API​​ v3的最新YouTube视频的PHP脚本

转载 作者:行者123 更新时间:2023-12-03 05:39:28 24 4
gpt4 key购买 nike

不久前,我通过在URL中的&id = username中添加用户名,制作了一个脚本,用于显示 channel 中最新的视频。最近,YouTube已开始将人们推向他们的新API v3,但我不确定如何更新代码以使其继续运行。可以在下面找到旧代码作为引用:

<html>
<head>
<link href='http://fonts.googleapis.com/css?family=Raleway:300' rel='stylesheet' type='text/css'>
<script language="javascript" type="text/javascript">
/*A very long java script to make the page responsive was removed from this snippet of code
*/
</script>
</head>
<body>
<?php
$feedURL = 'http://gdata.youtube.com/feeds/api/users/' . $_GET["id"] . '/uploads?max-results=1';

$headers = get_headers($feedURL, 1);
if ($headers[0] == 'HTTP/1.0 200 OK'):
$sxml = simplexml_load_file($feedURL);
$i=0;
foreach ($sxml->entry as $entry) {
$media = $entry->children('media', true);
$watch = (string)$media->group->player->attributes()->url;
$thumbnail = (string)$media->group->thumbnail[0]->attributes()->url;
$vid = (string)substr($thumbnail, 22, 11);
?>
<style>
.videothumb {
width:100%; }
.videotitle {
font-family: 'Raleway', Arial;
color: #e10707;
font-size: 20px;}
a:link {
text-decoration: none;
color: #e10707;
}

a:visited {
text-decoration: none;
color: #e10707;
}

a:hover {
text-decoration: none;
color: #e10707;
}

a:active {
text-decoration: none;
color: #e10707;
}
</style>
<div class="videoitem">
<!-- DEPRECATED <div class="videothumb"><a href="<?php echo $watch; ?>" class="watchvideo"><img src="<?php echo $thumbnail;?>" alt="<?php echo $media->group->title; ?>" /></a></div> -->
<div class="videothumb"><a href="<?php echo $watch; ?>" class="watchvideo"><img src="<?php echo 'https://img.youtube.com/vi/' . $vid . '/maxresdefault.jpg';?>" alt="<?php echo $media->group->title; ?>" width="100%"/></a></div>
<div class="videotitle">
<h3><a href="<?php echo $watch; ?>" class="watchvideo"><?php echo $media->group->title; ?></a></h3>
</div>
<?php if ($_GET["debug"] == "1"): ?>
<code>Debug Information: <br />
Watch link: <?php echo $watch; ?> <br />
Video ID: <?php echo $vid; ?>
</code>
<?php else: endif ?>
</div>
<?php $i++; if($i==3) { echo '<div class="clear small_v_margin"></div>'; $i=0; } } ?>
</body>
</html>
<?php else: ?>
<p style="font-size:60px;text-align:center;font-family:Arial">:(</p>
<?php
echo "An error happened. Please send an email to ____ and include which member page you are receiving this error on. Additionally please include the following ID: " . $_GET["id"] . " and " . $headers[0] ; endif
?>

最佳答案

您可以像在指南中一样检索 channel 的上传视频:https://developers.google.com/youtube/v3/migration-guide#videos

用户名已弃用,请改用 channel ID。但是,如果您仍在尝试查找仅知道旧用户名的 channel ,则可以使用forUsername parameter in channels.list call

关于php - 使用API​​ v3的最新YouTube视频的PHP脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30007011/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com