gpt4 book ai didi

php - PHP Youtube:缩略图机制上的“查看计数/持续时间”戳记

转载 作者:行者123 更新时间:2023-12-03 05:47:52 25 4
gpt4 key购买 nike

我在尝试显示时间为DURATION的缩略图时遇到了困难。该代码呈现缩略图,但是没有任何时间。此外, View 的结果是O View 的结果。其他所有内容都可以正确获取。

    <?php
error_reporting(E_ALL);
$feedURL = 'http://gdata.youtube.com/feeds/api/users/YOURUSERNAME/uploads?max-results=2';
$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;

// get <yt:duration> node for video length
$yt = $entry->children('http://gdata.youtube.com/feeds/api/users/YOURUSERNAME/uploads?max-results=2');
$attrs = $yt->duration->attributes();


// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/feeds/api/users/YOURUSERNAME/uploads?max-results=2');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];
?>


<div class="videoitem" style="height:">

<div class="videotitle" style="float:right; width:220px; ">
<h3 ><a href="<?php echo $watch; ?>" class="watchvideo"><?php echo $media->group->title; ?></a></h3>
<p><?php
echo sprintf("%0.2f", $length/60) . " min. |
{$viewCount} views<br/>\n"; ?>
</p>

</div>
<div class="videothumb" style="height:100px;"><a href="<?php echo $watch; ?>" class="watchvideo"><img src="<?php echo $thumbnail;?>" alt="<?php echo $media->group->title; ?>" width="150px" height="85px" /></a></div>

</div>
<?php $i++; if($i==3) { echo '<div class="clear small_v_margin"></div>'; $i=0; } } ?>

最佳答案

您将错误的URI传递给children方法。固定代码:

  // get <yt:duration> node for video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$length = $attrs['seconds'];

// get <yt:stats> node for viewer statistics
$yt = $entry->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$viewCount = $attrs['viewCount'];

关于php - PHP Youtube:缩略图机制上的“查看计数/持续时间”戳记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9916150/

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