2
0
Просмотр исходного кода

ZF-11948: Use HTTPS for YouTube API requests

Per a request from the YouTube API team, all client requests
should use HTTPS by default.

This patch implements this for Zend_Gdata_YouTube.

Patch-by: Jeffrey Posnick <jeffy@google.com>
Signed-off-by: Trevor Johns <trevorjohns@google.com>

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@24583 44c647ce-9c0f-0410-b52a-842ac1e357ba
tjohns 14 лет назад
Родитель
Сommit
86370eccbc

+ 6 - 6
demos/Zend/Gdata/YouTubeVideoApp/operations.php

@@ -336,7 +336,7 @@ function editVideoData($newVideoTitle, $newVideoDescription, $newVideoCategory,
 {
     $httpClient = getAuthSubHttpClient();
     $youTubeService = new Zend_Gdata_YouTube($httpClient);
-    $feed = $youTubeService->getVideoFeed('http://gdata.youtube.com/feeds/users/default/uploads');
+    $feed = $youTubeService->getVideoFeed('https://gdata.youtube.com/feeds/users/default/uploads');
     $videoEntryToUpdate = null;
 
     foreach($feed as $entry) {
@@ -430,7 +430,7 @@ function createUploadForm($videoTitle, $videoDescription, $videoCategory, $video
     $videoTagsArray = explode(' ', trim($videoTags));
     $newVideoEntry->setVideoTags(implode(', ', $videoTagsArray));
 
-    $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
+    $tokenHandlerUrl = 'https://gdata.youtube.com/action/GetUploadToken';
     try {
         $tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, $tokenHandlerUrl);
         if (loggingEnabled()) {
@@ -481,7 +481,7 @@ function deleteVideo($videoId)
 {
     $httpClient = getAuthSubHttpClient();
     $youTubeService = new Zend_Gdata_YouTube($httpClient);
-    $feed = $youTubeService->getVideoFeed('http://gdata.youtube.com/feeds/users/default/uploads');
+    $feed = $youTubeService->getVideoFeed('https://gdata.youtube.com/feeds/users/default/uploads');
     $videoEntryToDelete = null;
 
     foreach($feed as $entry) {
@@ -580,7 +580,7 @@ function clearSessionVar($name)
  */
 function generateAuthSubRequestLink($nextUrl = null)
 {
-    $scope = 'http://gdata.youtube.com';
+    $scope = 'https://gdata.youtube.com';
     $secure = false;
     $session = true;
 
@@ -791,7 +791,7 @@ function getRelatedVideos($videoId)
  */
 function getTopRatedVideosByUser($user)
 {
-    $userVideosUrl = 'http://gdata.youtube.com/feeds/users/' .
+    $userVideosUrl = 'https://gdata.youtube.com/feeds/users/' .
                    $user . '/uploads';
     $youTubeService = new Zend_Gdata_YouTube();
     $ytQuery = $youTubeService->newVideoQuery($userVideosUrl);
@@ -936,7 +936,7 @@ function createPlaylist($playlistTitle, $playlistDescription)
         return;
     }
 
-    $playlistFeedUrl = 'http://gdata.youtube.com/feeds/users/default/playlists';
+    $playlistFeedUrl = 'https://gdata.youtube.com/feeds/users/default/playlists';
 
     try {
         $updatedEntry = $youTubeService->insertEntry($newPlaylist, $playlistFeedUrl);

+ 1 - 1
demos/Zend/Gdata/YouTubeVideoBrowser/index.php

@@ -70,7 +70,7 @@ function findFlashUrl($entry)
  */
 function getTopRatedVideosByUser($user)
 {
-    $userVideosUrl = 'http://gdata.youtube.com/feeds/users/' .
+    $userVideosUrl = 'https://gdata.youtube.com/feeds/users/' .
                      $user . '/uploads';
     $yt = new Zend_Gdata_YouTube();
     $ytQuery = $yt->newVideoQuery($userVideosUrl);

+ 5 - 0
library/Zend/Gdata/App.php

@@ -42,6 +42,11 @@ require_once 'Zend/Version.php';
 require_once 'Zend/Gdata/App/MediaSource.php';
 
 /**
+ * Zend_Uri/Http
+ */
+require_once 'Zend/Uri/Http.php';
+
+/**
  * Provides Atom Publishing Protocol (APP) functionality.  This class and all
  * other components of Zend_Gdata_App are designed to work independently from
  * other Zend_Gdata components in order to interact with generic APP services.

+ 15 - 15
library/Zend/Gdata/YouTube.php

@@ -88,22 +88,22 @@ class Zend_Gdata_YouTube extends Zend_Gdata_Media
     const AUTH_SERVICE_NAME = 'youtube';
     const CLIENTLOGIN_URL = 'https://www.google.com/youtube/accounts/ClientLogin';
 
-    const STANDARD_TOP_RATED_URI = 'http://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
-    const STANDARD_MOST_VIEWED_URI = 'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
-    const STANDARD_RECENTLY_FEATURED_URI = 'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
-    const STANDARD_WATCH_ON_MOBILE_URI = 'http://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
+    const STANDARD_TOP_RATED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
+    const STANDARD_MOST_VIEWED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
+    const STANDARD_RECENTLY_FEATURED_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
+    const STANDARD_WATCH_ON_MOBILE_URI = 'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
 
     const STANDARD_TOP_RATED_URI_V2 =
-        'http://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
+        'https://gdata.youtube.com/feeds/api/standardfeeds/top_rated';
     const STANDARD_MOST_VIEWED_URI_V2 =
-        'http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
+        'https://gdata.youtube.com/feeds/api/standardfeeds/most_viewed';
     const STANDARD_RECENTLY_FEATURED_URI_V2 =
-        'http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
+        'https://gdata.youtube.com/feeds/api/standardfeeds/recently_featured';
     const STANDARD_WATCH_ON_MOBILE_URI_V2 =
-        'http://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
+        'https://gdata.youtube.com/feeds/api/standardfeeds/watch_on_mobile';
 
-    const USER_URI = 'http://gdata.youtube.com/feeds/api/users';
-    const VIDEO_URI = 'http://gdata.youtube.com/feeds/api/videos';
+    const USER_URI = 'https://gdata.youtube.com/feeds/api/users';
+    const VIDEO_URI = 'https://gdata.youtube.com/feeds/api/videos';
     const PLAYLIST_REL = 'http://gdata.youtube.com/schemas/2007#playlist';
     const USER_UPLOADS_REL = 'http://gdata.youtube.com/schemas/2007#user.uploads';
     const USER_PLAYLISTS_REL = 'http://gdata.youtube.com/schemas/2007#user.playlists';
@@ -113,9 +113,9 @@ class Zend_Gdata_YouTube extends Zend_Gdata_Media
     const VIDEO_RESPONSES_REL = 'http://gdata.youtube.com/schemas/2007#video.responses';
     const VIDEO_RATINGS_REL = 'http://gdata.youtube.com/schemas/2007#video.ratings';
     const VIDEO_COMPLAINTS_REL = 'http://gdata.youtube.com/schemas/2007#video.complaints';
-    const ACTIVITY_FEED_URI = 'http://gdata.youtube.com/feeds/api/events';
+    const ACTIVITY_FEED_URI = 'https://gdata.youtube.com/feeds/api/events';
     const FRIEND_ACTIVITY_FEED_URI =
-        'http://gdata.youtube.com/feeds/api/users/default/friendsactivity';
+        'https://gdata.youtube.com/feeds/api/users/default/friendsactivity';
 
     /**
      * The URI of the in-reply-to schema for comments in reply to
@@ -132,7 +132,7 @@ class Zend_Gdata_YouTube extends Zend_Gdata_Media
      * @var string
      */
     const INBOX_FEED_URI =
-        'http://gdata.youtube.com/feeds/api/users/default/inbox';
+        'https://gdata.youtube.com/feeds/api/users/default/inbox';
 
     /**
      * The maximum number of users for which activity can be requested for,
@@ -697,7 +697,7 @@ class Zend_Gdata_YouTube extends Zend_Gdata_Media
      * @return array An array containing a token and URL
      */
     public function getFormUploadToken($videoEntry,
-        $url='http://gdata.youtube.com/action/GetUploadToken')
+        $url='https://gdata.youtube.com/action/GetUploadToken')
     {
         if ($url != null && is_string($url)) {
             // $response is a Zend_Http_response object
@@ -834,7 +834,7 @@ class Zend_Gdata_YouTube extends Zend_Gdata_Media
             $messageEntry->setSummary($this->newSummary($body));
         }
 
-        $insertUrl = 'http://gdata.youtube.com/feeds/api/users/' .
+        $insertUrl = 'https://gdata.youtube.com/feeds/api/users/' .
             $recipientUserName . '/inbox';
         $response = $this->insertEntry($messageEntry, $insertUrl,
             'Zend_Gdata_YouTube_InboxEntry');

+ 7 - 7
tests/Zend/Gdata/YouTubeOnlineTest.php

@@ -104,7 +104,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
         $entry = $this->gdata->getVideoEntry('66wj2g5yz0M');
         $this->assertEquals('TestMovie', $entry->title->text);
 
-        $entry = $this->gdata->getVideoEntry(null, 'http://gdata.youtube.com/feeds/api/videos/66wj2g5yz0M');
+        $entry = $this->gdata->getVideoEntry(null, 'https://gdata.youtube.com/feeds/api/videos/66wj2g5yz0M');
         $this->assertEquals('TestMovie', $entry->title->text);
     }
 
@@ -335,7 +335,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
         $titleString = $this->generateRandomString(10);
         $newPlaylist->title = $yt->newTitle()->setText($titleString);
         $newPlaylist->summary = $yt->newSummary()->setText('testing');
-        $postUrl = 'http://gdata.youtube.com/feeds/api/users/default/playlists';
+        $postUrl = 'https://gdata.youtube.com/feeds/api/users/default/playlists';
         $successfulInsertion = true;
 
         try {
@@ -454,7 +454,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
             $channelToSubscribeTo));
 
         $postUrl =
-            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
+            'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
         $successPosting = true;
         $message = null;
@@ -549,7 +549,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
             $usernameOfFavoritesToSubscribeTo));
 
         $postUrl =
-            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
+            'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
         $successPosting = true;
         $message = null;
@@ -644,7 +644,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
             $playlistIdToSubscribeTo));
 
         $postUrl =
-            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
+            'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
         $successPosting = true;
         $message = null;
@@ -737,7 +737,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
             $queryStringToSubscribeTo));
 
         $postUrl =
-            'http://gdata.youtube.com/feeds/api/users/default/subscriptions';
+            'https://gdata.youtube.com/feeds/api/users/default/subscriptions';
 
         $successPosting = true;
         $message = null;
@@ -1009,7 +1009,7 @@ class Zend_Gdata_YouTubeOnlineTest extends PHPUnit_Framework_TestCase
         $youtube->setMajorProtocolVersion(2);
 
         $mostDiscussedFeed = $youtube->getVideoFeed(
-            'http://gdata.youtube.com/feeds/api/standardfeeds/most_discussed');
+            'https://gdata.youtube.com/feeds/api/standardfeeds/most_discussed');
 
         // get first entry
         $mostDiscussedFeed->rewind();

+ 1 - 1
tests/Zend/Gdata/YouTubeTest.php

@@ -49,7 +49,7 @@ class Zend_Gdata_YouTubeTest extends PHPUnit_Framework_TestCase
     public function testGetFormUploadTokenResponseHandler()
     {
         $responseArray = Zend_Gdata_YouTube::parseFormUploadTokenResponse($this->responseText);
-        $this->assertEquals('http://uploads.gdata.youtube.com/action/FormDataUpload/AIwbF1_JjEQ9cGTjEAd5FKwV42SeNWJexmc5y7XR-eFj24uqbqU6NRcxKJW_4R-sYISLxQ',
+        $this->assertEquals('https://uploads.gdata.youtube.com/action/FormDataUpload/AIwbF1_JjEQ9cGTjEAd5FKwV42SeNWJexmc5y7XR-eFj24uqbqU6NRcxKJW_4R-sYISLxQ',
                             $responseArray['url']);
         $this->assertEquals('AIwbFAQ21fImpR2iYPaFnfuCvfbCB3qBxl5qXiZlpH3lfkungiSPoyw1iOM1gFB6Nx-wmY-kjprNT3qtdp7LJCLfngn11Ne_X9Jd44Vz8AzygtEtaDGyib5tnri0O0-V5pwcAPCHIJurOMsOpA2zInW8V8qHk2S2LheXfTXVbqc0Li9iCBpsoBGbykYU0moNoyGAaKRbSBD0oPnCv6v9Rll5Zjvivi2hQt-Br2JDb9wVeLv3qyAFaeyN6X6k32RyaAHs_n8d8d_oSriQmvS8g1HxSCS4dnoGL7tafQ4SBqnrQEb-hxFeu1ZrAwCLv',
                             $responseArray['token']);