From 06f945f27840b53e57795dadbc38e76f7e11ab1c Mon Sep 17 00:00:00 2001 From: Horus3 Date: Mon, 24 Feb 2014 16:42:14 +0100 Subject: init --- .../manual/core/en/zend.gdata.youtube.html | 758 +++++++++++++++++++++ 1 file changed, 758 insertions(+) create mode 100644 zend/documentation/manual/core/en/zend.gdata.youtube.html (limited to 'zend/documentation/manual/core/en/zend.gdata.youtube.html') diff --git a/zend/documentation/manual/core/en/zend.gdata.youtube.html b/zend/documentation/manual/core/en/zend.gdata.youtube.html new file mode 100644 index 0000000..18e43ba --- /dev/null +++ b/zend/documentation/manual/core/en/zend.gdata.youtube.html @@ -0,0 +1,758 @@ + + + + + Using the YouTube Data API - Zend Framework Manual + + + + + + + + +
+ + + + + + + + +
+ Using Picasa Web Albums + + + + +
+
+

Using the YouTube Data API

+ + +

+ The YouTube Data API offers read and write access to YouTube's content. + Users can perform unauthenticated requests to Google Data feeds to + retrieve feeds of popular videos, comments, public information about + YouTube user profiles, user playlists, favorites, subscriptions and so on. +

+ +

+ For more information on the YouTube Data API, please refer + to the official » PHP + Developer's Guide on code.google.com. +

+ +

Authentication

+ + +

+ The YouTube Data API allows read-only access to public data, which + does not require authentication. For any write requests, a user + needs to authenticate either using ClientLogin or AuthSub authentication. Please refer + to the » Authentication + section in the PHP Developer's Guide for more detail. +

+
+ +

Developer Keys and Client ID

+ + +

+ A developer key identifies the YouTube developer that is submitting + an API request. A client ID identifies your application for logging + and debugging purposes. Please visit » http://code.google.com/apis/youtube/dashboard/ + to obtain a developer key and client ID. The example below demonstrates how to pass the + developer key and client ID to the » Zend_Gdata_YouTube + service object. +

+ +

Example #1 Passing a Developer Key and ClientID to Zend_Gdata_YouTube

+ + +
  1. $yt = new Zend_Gdata_YouTube($httpClient,
  2. +
  3.                              $applicationId,
  4. +
  5.                              $clientId,
  6. +
  7.                              $developerKey);
+ +
+
+ +

Retrieving public video feeds

+ + +

+ The YouTube Data API provides numerous feeds that return a list of + videos, such as standard feeds, related videos, video responses, + user's uploads, and user's favorites. For example, the + user's uploads feed returns all videos uploaded by a specific user. See the » YouTube + API reference guide for a detailed list of available + feeds. +

+ +

Searching for videos by metadata

+ + +

+ You can retrieve a list of videos that match specified + search criteria, using the YouTubeQuery class. The following query + looks for videos which contain the word "cat" in their + metadata, starting with the 10th video and displaying 20 + videos per page, ordered by the view count. +

+ +

Example #2 Searching for videos

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $query = $yt->newVideoQuery();
  4. +
  5. $query->videoQuery = 'cat';
  6. +
  7. $query->startIndex = 10;
  8. +
  9. $query->maxResults = 20;
  10. +
  11. $query->orderBy = 'viewCount';
  12. +
  13.  
  14. +
  15. echo $query->queryUrl . "\n";
  16. +
  17. $videoFeed = $yt->getVideoFeed($query);
  18. +
  19.  
  20. +
  21. foreach ($videoFeed as $videoEntry) {
  22. +
  23.     echo "---------VIDEO----------\n";
  24. +
  25.     echo "Title: " . $videoEntry->getVideoTitle() . "\n";
  26. +
  27.     echo "\nDescription:\n";
  28. +
  29.     echo $videoEntry->getVideoDescription();
  30. +
  31.     echo "\n\n\n";
  32. +
  33. }
+ +
+ +

+ For more details on the different query parameters, please refer to the » + Reference Guide. The available helper functions in » Zend_Gdata_YouTube_VideoQuery + for each of these parameters are described in more detail in the » PHP + Developer's Guide. +

+
+ +

Searching for videos by categories and tags/keywords

+ + +

+ Searching for videos in specific categories is done by generating a » specially + formatted URL. For example, to search for + comedy videos which contain the keyword dog: +

+ +

Example #3 Searching for videos in specific categories

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $query = $yt->newVideoQuery();
  4. +
  5. $query->category = 'Comedy/dog';
  6. +
  7.  
  8. +
  9. echo $query->queryUrl . "\n";
  10. +
  11. $videoFeed = $yt->getVideoFeed($query);
+ +
+
+ +

Retrieving standard feeds

+ + +

+ The YouTube Data API has a number of » standard + feeds. These standard feeds can be retrieved as » Zend_Gdata_YouTube_VideoFeed + objects using the specified URLs, using the predefined constants + within the » Zend_Gdata_YouTube + class (Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI for example) or + using the predefined helper methods (see code listing below). +

+ +

+ To retrieve the top rated videos using the helper method: +

+ +

Example #4 Retrieving a standard video feed

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $videoFeed = $yt->getTopRatedVideoFeed();
+ +
+ +

+ There are also query parameters to specify the time period + over which the standard feed is computed. +

+ +

+ For example, to retrieve the top rated videos for today: +

+ +

Example #5 Using a Zend_Gdata_YouTube_VideoQuery to Retrieve Videos

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $query = $yt->newVideoQuery();
  4. +
  5. $query->setTime('today');
  6. +
  7. $videoFeed = $yt->getTopRatedVideoFeed($query);
+ +
+ +

+ Alternatively, you could just retrieve the feed using the + URL: +

+ +

Example #6 Retrieving a video feed by URL

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $url = 'http://gdata.youtube.com/feeds/standardfeeds/top_rated?time=today'
  4. +
  5. $videoFeed = $yt->getVideoFeed($url);
+ +
+
+ +

Retrieving videos uploaded by a user

+ + +

+ You can retrieve a list of videos uploaded by a particular user + using a simple helper method. This example retrieves videos + uploaded by the user 'liz'. +

+ +

Example #7 Retrieving videos uploaded by a specific user

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $videoFeed = $yt->getUserUploads('liz');
+ +
+
+ +

Retrieving videos favorited by a user

+ + +

+ You can retrieve a list of a user's favorite videos + using a simple helper method. This example retrieves videos + favorited by the user 'liz'. +

+ +

Example #8 Retrieving a user's favorite videos

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $videoFeed = $yt->getUserFavorites('liz');
+ +
+
+ +

Retrieving video responses for a video

+ + +

+ You can retrieve a list of a video's video responses + using a simple helper method. This example retrieves video + response for a video with the ID 'abc123813abc'. +

+ +

Example #9 Retrieving a feed of video responses

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $videoFeed = $yt->getVideoResponseFeed('abc123813abc');
+ +
+
+
+ +

Retrieving video comments

+ + +

+ The comments for each YouTube video can be retrieved in + several ways. To retrieve the comments for the video with + the ID 'abc123813abc', use the following code: +

+ +

Example #10 Retrieving a feed of video comments from a video ID

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $commentFeed = $yt->getVideoCommentFeed('abc123813abc');
  4. +
  5.  
  6. +
  7. foreach ($commentFeed as $commentEntry) {
  8. +
  9.     echo $commentEntry->title->text . "\n";
  10. +
  11.     echo $commentEntry->content->text . "\n\n\n";
  12. +
  13. }
+ +
+ +

+ Comments can also be retrieved for a video if you have a copy of the » Zend_Gdata_YouTube_VideoEntry + object: +

+ +

Example #11 Retrieving a Feed of Video Comments from a Zend_Gdata_YouTube_VideoEntry

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $videoEntry = $yt->getVideoEntry('abc123813abc');
  4. +
  5. // we don't know the video ID in this example, but we do have the URL
  6. +
  7. $commentFeed = $yt->getVideoCommentFeed(null,
  8. +
  9.                                         $videoEntry->comments->href);
+ +
+
+ +

Retrieving playlist feeds

+ + +

+ The YouTube Data API provides information about users, including + profiles, playlists, subscriptions, and more. +

+ +

Retrieving the playlists of a user

+ + +

+ The library provides a helper method to retrieve + the playlists associated with a given user. To retrieve the + playlists for the user 'liz': +

+ +

Example #12 Retrieving the playlists of a user

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $playlistListFeed = $yt->getPlaylistListFeed('liz');
  4. +
  5.  
  6. +
  7. foreach ($playlistListFeed as $playlistEntry) {
  8. +
  9.     echo $playlistEntry->title->text . "\n";
  10. +
  11.     echo $playlistEntry->description->text . "\n";
  12. +
  13.     echo $playlistEntry->getPlaylistVideoFeedUrl() . "\n\n\n";
  14. +
  15. }
+ +
+
+ +

Retrieving a specific playlist

+ + +

+ The library provides a helper method to retrieve + the videos associated with a given playlist. To retrieve the + playlists for a specific playlist entry: +

+ +

Example #13 Retrieving a specific playlist

+ + +
  1. $feedUrl = $playlistEntry->getPlaylistVideoFeedUrl();
  2. +
  3. $playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
+ +
+
+
+ +

Retrieving a list of a user's subscriptions

+ + +

+ A user can have several types of subscriptions: channel + subscription, tag subscription, or favorites subscription. A » Zend_Gdata_YouTube_SubscriptionEntry + is used to represent individual subscriptions. +

+ +

+ To retrieve all subscriptions for the user 'liz': +

+ +

Example #14 Retrieving all subscriptions for a user

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $subscriptionFeed = $yt->getSubscriptionFeed('liz');
  4. +
  5.  
  6. +
  7. foreach ($subscriptionFeed as $subscriptionEntry) {
  8. +
  9.     echo $subscriptionEntry->title->text . "\n";
  10. +
  11. }
+ +
+
+ +

Retrieving a user's profile

+ + +

+ You can retrieve the public profile information + for any YouTube user. To retrieve the profile + for the user 'liz': +

+ +

Example #15 Retrieving a user's profile

+ + +
  1. $yt = new Zend_Gdata_YouTube();
  2. +
  3. $userProfile = $yt->getUserProfile('liz');
  4. +
  5. echo "username: " . $userProfile->username->text . "\n";
  6. +
  7. echo "age: " . $userProfile->age->text . "\n";
  8. +
  9. echo "hometown: " . $userProfile->hometown->text . "\n";
+ +
+
+ +

Uploading Videos to YouTube

+ + +

+ Please make sure to review the diagrams in the » protocol + guide on code.google.com for a high-level + overview of the upload process. Uploading videos can be done in one of + two ways: either by uploading the video directly or by sending just the video + meta-data and having a user upload the video through an HTML form. +

+ +

+ In order to upload a video directly, you must first construct a new » Zend_Gdata_YouTube_VideoEntry + object and specify some required meta-data. The following example shows uploading the + Quicktime video "mytestmovie.mov" to YouTube with the following properties: +

+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Metadata used in the code-sample below
PropertyValue
TitleMy Test Movie
CategoryAutos
Keywordscars, funny
DescriptionMy description
Filenamemytestmovie.mov
File MIME typevideo/quicktime
Video private?FALSE
Video location37, -122 (lat, long)
Developer Tagsmydevelopertag, anotherdevelopertag
+ + +

+ The code below creates a blank » Zend_Gdata_YouTube_VideoEntry + to be uploaded. A » Zend_Gdata_App_MediaFileSource + object is then used to hold the actual video file. Under the hood, the » Zend_Gdata_YouTube_Extension_MediaGroup + object is used to hold all of the video's meta-data. Our helper methods detailed below + allow you to just set the video meta-data without having to worry about the media group + object. The $uploadUrl is the location where the new entry gets posted to. + This can be specified either with the $userName of the + currently authenticated user, or, alternatively, you can simply use the + string 'default' to refer to the currently authenticated user. +

+ +

Example #16 Uploading a video

+ + +
  1. $yt = new Zend_Gdata_YouTube($httpClient);
  2. +
  3. $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  4. +
  5.  
  6. +
  7. $filesource = $yt->newMediaFileSource('mytestmovie.mov');
  8. +
  9. $filesource->setContentType('video/quicktime');
  10. +
  11. $filesource->setSlug('mytestmovie.mov');
  12. +
  13.  
  14. +
  15. $myVideoEntry->setMediaSource($filesource);
  16. +
  17.  
  18. +
  19. $myVideoEntry->setVideoTitle('My Test Movie');
  20. +
  21. $myVideoEntry->setVideoDescription('My Test Movie');
  22. +
  23. // Note that category must be a valid YouTube category !
  24. +
  25. $myVideoEntry->setVideoCategory('Comedy');
  26. +
  27.  
  28. +
  29. // Set keywords, note that this must be a comma separated string
  30. +
  31. // and that each keyword cannot contain whitespace
  32. +
  33. $myVideoEntry->SetVideoTags('cars, funny');
  34. +
  35.  
  36. +
  37. // Optionally set some developer tags
  38. +
  39. $myVideoEntry->setVideoDeveloperTags(array('mydevelopertag',
  40. +
  41.                                            'anotherdevelopertag'));
  42. +
  43.  
  44. +
  45. // Optionally set the video's location
  46. +
  47. $yt->registerPackage('Zend_Gdata_Geo');
  48. +
  49. $yt->registerPackage('Zend_Gdata_Geo_Extension');
  50. +
  51. $where = $yt->newGeoRssWhere();
  52. +
  53. $position = $yt->newGmlPos('37.0 -122.0');
  54. +
  55. $where->point = $yt->newGmlPoint($position);
  56. +
  57. $myVideoEntry->setWhere($where);
  58. +
  59.  
  60. +
  61. // Upload URI for the currently authenticated user
  62. +
  63. $uploadUrl =
  64. +
  65.     'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
  66. +
  67.  
  68. +
  69. // Try to upload the video, catching a Zend_Gdata_App_HttpException
  70. +
  71. // if availableor just a regular Zend_Gdata_App_Exception
  72. +
  73.  
  74. +
  75. try {
  76. +
  77.     $newEntry = $yt->insertEntry($myVideoEntry,
  78. +
  79.                                  $uploadUrl,
  80. +
  81.                                  'Zend_Gdata_YouTube_VideoEntry');
  82. +
  83. } catch (Zend_Gdata_App_HttpException $httpException) {
  84. +
  85.     echo $httpException->getRawResponseBody();
  86. +
  87. } catch (Zend_Gdata_App_Exception $e) {
  88. +
  89.     echo $e->getMessage();
  90. +
  91. }
+ +
+ +

+ To upload a video as private, simply use: $myVideoEntry->setVideoPrivate(); prior to + performing the upload. $videoEntry->isVideoPrivate() can be used to check whether a + video entry is private or not. +

+
+ +

Browser-based upload

+ + +

+ Browser-based uploading is performed almost identically to direct uploading, + except that you do not attach a » Zend_Gdata_App_MediaFileSource + object to the » Zend_Gdata_YouTube_VideoEntry + you are constructing. Instead you simply submit all of your video's meta-data to receive + back a token element which can be used to construct an HTML upload + form. +

+ +

Example #17 Browser-based upload

+ + +
  1. $yt = new Zend_Gdata_YouTube($httpClient);
  2. +
  3.  
  4. +
  5. $myVideoEntry= new Zend_Gdata_YouTube_VideoEntry();
  6. +
  7. $myVideoEntry->setVideoTitle('My Test Movie');
  8. +
  9. $myVideoEntry->setVideoDescription('My Test Movie');
  10. +
  11.  
  12. +
  13. // Note that category must be a valid YouTube category
  14. +
  15. $myVideoEntry->setVideoCategory('Comedy');
  16. +
  17. $myVideoEntry->SetVideoTags('cars, funny');
  18. +
  19.  
  20. +
  21. $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
  22. +
  23. $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
  24. +
  25. $tokenValue = $tokenArray['token'];
  26. +
  27. $postUrl = $tokenArray['url'];
+ +
+ +

+ The above code prints out a link and a token that is used to construct an + HTML form to display in the user's browser. A simple example form is + shown below with $tokenValue representing the content of the returned token element, + as shown being retrieved from $myVideoEntry above. In order for the user + to be redirected to your website after submitting the form, make sure to + append a $nextUrl parameter to the $postUrl above, which functions in the + same way as the $next parameter of an AuthSub link. The only difference is + that here, instead of a single-use token, a status and an id variable are + returned in the URL. +

+ +

Example #18 Browser-based upload: Creating the HTML form

+ + +
  1. // place to redirect user after upload
  2. +
  3. $nextUrl = 'http://mysite.com/youtube_uploads';
  4. +
  5.  
  6. +
  7. $form = '<form action="'. $postUrl .'?nexturl='. $nextUrl .
  8. +
  9.         '" method="post" enctype="multipart/form-data">'.
  10. +
  11.         '<input name="file" type="file"/>'.
  12. +
  13.         '<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
  14. +
  15.         '<input value="Upload Video File" type="submit" />'.
  16. +
  17.         '</form>';
+ +
+
+ +

Checking upload status

+ + +

+ After uploading a video, it will immediately be visible in an + authenticated user's uploads feed. However, it will not be public on + the site until it has been processed. Videos that have been rejected or + failed to upload successfully will also only be in the authenticated + user's uploads feed. The following code checks the status of a » Zend_Gdata_YouTube_VideoEntry + to see if it is not live yet or if it has been rejected. +

+ +

Example #19 Checking video upload status

+ + +
  1. try {
  2. +
  3.     $control = $videoEntry->getControl();
  4. +
  5. } catch (Zend_Gdata_App_Exception $e) {
  6. +
  7.     echo $e->getMessage();
  8. +
  9. }
  10. +
  11.  
  12. +
  13. if ($control instanceof Zend_Gdata_App_Extension_Control) {
  14. +
  15.     if ($control->getDraft() != null &&
  16. +
  17.         $control->getDraft()->getText() == 'yes') {
  18. +
  19.         $state = $videoEntry->getVideoState();
  20. +
  21.  
  22. +
  23.         if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
  24. +
  25.             print 'Upload status: '
  26. +
  27.                   . $state->getName()
  28. +
  29.                   .' '. $state->getText();
  30. +
  31.         } else {
  32. +
  33.             print 'Not able to retrieve the video status information'
  34. +
  35.                   .' yet. ' . "Please try again shortly.\n";
  36. +
  37.         }
  38. +
  39.     }
  40. +
  41. }
+ +
+
+ +

Other Functions

+ + +

+ In addition to the functionality described above, the YouTube API + contains many other functions that allow you to modify video meta-data, + delete video entries and use the full range of community features on the site. Some of + the community features that can be modified through the API include: + ratings, comments, playlists, subscriptions, user profiles, contacts and messages. +

+

+ Please refer to the full documentation available in the » PHP Developer's + Guide on code.google.com. +

+
+
+
+ + + + + + + + + +
+ Using Picasa Web Albums + + + + +
+
+ +
+ + \ No newline at end of file -- cgit v1.2.3