ZF-9479: Zend_Gdata_Youtube does not work with v2.0 API
Description
Try the following code:
require_once 'Zend/Gdata/Youtube.php';
$yt = new Zend_Gdata_YouTube();
$yt->setMajorProtocolVersion(2);
$query = $yt->newVideoQuery();
$query->videoQuery = 'zend framework';
$query->startIndex = 0;
$query->maxResults = 10;
$query->orderBy = 'viewCount';
$query->safeSearch = 'strict';
$videoFeed = $yt->getVideoFeed($query);
The 2.0 headers are properly sent but the query is still generated with 1.0 params. After doing some research I found out that the "getQueryUrl"-function in Zend_Gdata_YouTube_VideoQuery can have 2 arguments with version numbers. The function which calls this (getVideoFeed() in Zend_Gdata_YouTube) does NOT provide the version at all so it will never trigger the function to use 2.0 params instead of 1.0 params.
I changed line 259 in Zend_Gdata_YouTube from:
$uri = $location->getQueryUrl();
to:
$uri = $location->getQueryUrl($this->getMajorProtocolVersion());
to make it work for now but changing the library myself isnt a very wise thing to do. I suggest this will be taken care of quickly since the 2.0 version seems useless for Zend Framework right now. If I am wrong about the usage of this please document this (better).
Comments
Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T04:42:14.000+0000
Confirmed. Unit test:
When running the above example I receive a 400 status code + the following body:
After applying the suggested fix:
The unit test passes
Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T04:46:18.000+0000
Attached patch which fixes all calls to {{getQueryUrl}} from {{Zend_Gdata_YouTube}}
Posted by Adam Lundrigan (adamlundrigan) on 2012-05-12T03:35:11.000+0000
Fixed in trunk (1.12.0): r24796