Issues

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

Confirmed. Unit test:


Index: tests/Zend/Gdata/YouTubeOnlineTest.php
===================================================================
--- tests/Zend/Gdata/YouTubeOnlineTest.php      (revision 24628)
+++ tests/Zend/Gdata/YouTubeOnlineTest.php      (working copy)
@@ -263,6 +263,23 @@
             }
         }
     }
+    /**
+     * @group ZF-9479
+     */
+    public function testPerformV2Query()
+    {
+        $this->gdata->setMajorProtocolVersion(2);
+        $query = $this->gdata->newVideoQuery();
+        $query->videoQuery = 'zend framework';
+        $query->startIndex = 0;
+        $query->maxResults = 10;
+        $query->orderBy = 'viewCount';
+        $query->safeSearch = 'strict';
+        $videoFeed = $this->gdata->getVideoFeed($query);
+        $this->assertTrue(count($videoFeed->entry) > 0,
+            'Could not retrieve a single entry for location search:' .
+            $query->getQueryUrl(2));
+    }

     public function testPerformV2Query_Location()
     {

When running the above example I receive a 400 status code + the following body:


GDataInvalidRequestUriExceptionThe parameter 'vq' is not available in this version. Please use 'q' instead.

After applying the suggested fix:


Index: library/Zend/Gdata/YouTube.php
===================================================================
--- library/Zend/Gdata/YouTube.php      (revision 24628)
+++ library/Zend/Gdata/YouTube.php      (working copy)
@@ -256,7 +256,7 @@
         if ($location == null) {
             $uri = self::VIDEO_URI;
         } else if ($location instanceof Zend_Gdata_Query) {
-            $uri = $location->getQueryUrl();
+            $uri = $location->getQueryUrl($this->getMajorProtocolVersion());
         } else {
             $uri = $location;
         }

The unit test passes

Attached patch which fixes all calls to {{getQueryUrl}} from {{Zend_Gdata_YouTube}}

Fixed in trunk (1.12.0): r24796