gpt4 book ai didi

php - 我的YouTube脚本出现PHP fatal error

转载 作者:行者123 更新时间:2023-12-03 06:24:08 36 4
gpt4 key购买 nike

我在YouTube php脚本上收到以下错误:

Fatal error: Call to a member function getAttribute() on a non-object
in /home/web/public_html/youtube/home.php on line 8

代码是:
<?php
$vidID= $_GET['id'];
$url = "http://gdata.youtube.com/feeds/api/videos/". $vidID;
$doc = new DOMDocument;
$doc->load($url);
$title = $doc->getElementsByTagName("title")->item(0)->nodeValue;
$published = $doc->getElementsByTagName("published")->item(0)->nodeValue;
$duration = $doc->getElementsByTagName('duration')->item(0)->getAttribute('seconds');
//$durationformatted = ;str_pad(floor($duration/60), 2, '0', STR_PAD_LEFT) . ':' . str_pad($duration%60, 2, '0', STR_PAD_LEFT); not working atm :/
$name = $doc->getElementsByTagName("name")->item(0)->nodeValue;
$commentcount = $doc->getElementsByTagName('feedLink')->item(0)->getAttribute('countHint');
$averagerating = $doc->getElementsByTagName('rating')->item(0)->getAttribute('average');
$numberofraters = $doc->getElementsByTagName('rating')->item(0)->getAttribute('numRaters');
$statisticsviewcount = $doc->getElementsByTagName('statistics')->item(0)->getAttribute('viewCount');

echo "Title: ".$title."\nDuration: ".$duration." seconds\nPublished: ".$published."\nUsername/channel: ".$name."\nTotal Comments: ".$commentcount."\nCategory: ".$category."\nAverage rating: ".$averagerating." out of 5\nNumber of raters: ".$numberofraters."\nView count: ".$statisticsviewcount."\n";

?>

我怎样才能解决这个问题?

最佳答案

为什么不先测试属性?

if( is_object( $node ) && $node->hasAttribute( $attrib ) ).... etc

关于php - 我的YouTube脚本出现PHP fatal error ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29367173/

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