YouTube PHP API - Zend_Gdata_App_HttpException

别来无恙 提交于 2020-01-17 03:11:09

问题


I've got a working website, which uses youtube api. Everything was fine but today I noticed I get error while using this api:

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 <?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>' in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php:700 Stack trace: #0 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'http://gdata.yo...', Array, NULL, NULL, NULL) #1 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(861): Zend_Gdata->performHttpRequest('GET', 'http://gdata.yo...', Array) #2 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(754): Zend_Gdata_App->get('http://gdata.yo...', NULL) #3 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(205): Zend_Gdata_App->importUrl('http://gdata.yo...', 'Zend_Gdata_YouT...', NULL) #4 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php( in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php on line 700

my code looks somehow like this:

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Uri_Http');
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->setQuery($searchTerms);
$query->setStartIndex($index2);
$query->setMaxResults(10);
$query->setOrderBy($order);

$videoFeed = $yt->getVideoFeed($query);

foreach ($videoFeed as $videoEntry) {
    $videoThumbnails = $videoEntry->mediaGroup->thumbnail[0]->url;
    $title = $videoEntry->mediaGroup->title;
    $vidId = $videoEntry->getVideoId();
    $vidDescription = $videoEntry->mediaGroup->description;
    $duration = $videoEntry->mediaGroup->duration->seconds;
    $rating = round($videoEntry->rating->average,1)." out of 5";
    echo "info...";
}

Funny thing is that it sometime works and sometime does not... I don't really know why, any help appreciated, thanks.


回答1:


As stated in comments, I just had to limit the access and lower the calls. Thanks Slava.



来源:https://stackoverflow.com/questions/6562083/youtube-php-api-zend-gdata-app-httpexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!