Issues

ZF-9479: Zend_Gdata_Youtube does not work with v2.0 API

Issue Type: Bug Created: 2010-03-19T03:30:00.000+0000 Last Updated: 2012-05-12T03:35:11.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: R Slootjes (rslootjes) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Gdata

  • zf-crteam-review

Related issues: Attachments: - ZF-9479.patch

Description

Try the following code:

<pre class="highlight">
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:

<pre class="highlight">
$uri = $location->getQueryUrl();

to:

<pre class="highlight">
$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:

<pre class="highlight">
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:

<pre class="highlight">
GDataInvalidRequestUriExceptionThe parameter 'vq' is not available in this version. Please use 'q' instead.

After applying the suggested fix:

<pre class="highlight">
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

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

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts