Zend_Gdata_YouTube.xml 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.gdata.youtube">
  4. <title>Using the YouTube Data API</title>
  5. <para>
  6. The YouTube Data <acronym>API</acronym> offers read and write access to YouTube's content.
  7. Users can perform unauthenticated requests to Google Data feeds to
  8. retrieve feeds of popular videos, comments, public information about
  9. YouTube user profiles, user playlists, favorites, subscriptions and so on.
  10. </para>
  11. <para>
  12. For more information on the YouTube Data <acronym>API</acronym>, please refer
  13. to the official <ulink url="http://code.google.com/apis/youtube/developers_guide_php.html">
  14. <acronym>PHP</acronym> Developer's Guide</ulink> on code.google.com.
  15. </para>
  16. <sect2 id="zend.gdata.youtube.authentication">
  17. <title>Authentication</title>
  18. <para>
  19. The YouTube Data <acronym>API</acronym> allows read-only access to public data, which
  20. does not require authentication. For any write requests, a user
  21. needs to authenticate either using ClientLogin or AuthSub authentication. Please refer to the <ulink url="http://code.google.com/apis/youtube/developers_guide_php.html#Authentication">Authentication section in the <acronym>PHP</acronym> Developer's Guide</ulink> for more detail.
  22. </para>
  23. </sect2>
  24. <sect2 id="zend.gdata.youtube.developer_key">
  25. <title>Developer Keys and Client ID</title>
  26. <para>
  27. A developer key identifies the YouTube developer that is submitting
  28. an <acronym>API</acronym> request. A client ID identifies your application for logging
  29. and debugging purposes. Please visit <ulink url="http://code.google.com/apis/youtube/dashboard/">http://code.google.com/apis/youtube/dashboard/</ulink> to obtain a developer key and client ID. The example below demonstrates how to pass the developer key and client ID to the <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html">Zend_Gdata_YouTube</ulink> service object.
  30. </para>
  31. <example id="zend.gdata.youtube.developer_key.example">
  32. <title>Passing a Developer Key and ClientID to Zend_Gdata_YouTube</title>
  33. <programlisting language="php"><![CDATA[
  34. $yt = new Zend_Gdata_YouTube($httpClient,
  35. $applicationId,
  36. $clientId,
  37. $developerKey);
  38. ]]></programlisting>
  39. </example>
  40. </sect2>
  41. <sect2 id="zend.gdata.youtube.videos">
  42. <title>Retrieving public video feeds</title>
  43. <para>
  44. The YouTube Data <acronym>API</acronym> provides numerous feeds that return a list of
  45. videos, such as standard feeds, related videos, video responses,
  46. user's uploads, and user's favorites. For example, the
  47. user's uploads feed returns all videos uploaded by a specific user.
  48. See the <ulink url="http://code.google.com/apis/youtube/reference.html#Video_Feeds">
  49. YouTube <acronym>API</acronym> reference guide</ulink> for a detailed list of available feeds.
  50. </para>
  51. <sect3 id="zend.gdata.youtube.videos.searching">
  52. <title>Searching for videos by metadata</title>
  53. <para>
  54. You can retrieve a list of videos that match specified
  55. search criteria, using the YouTubeQuery class. The following query
  56. looks for videos which contain the word "cat" in their
  57. metadata, starting with the 10th video and displaying 20
  58. videos per page, ordered by the view count.
  59. </para>
  60. <example id="zend.gdata.youtube.videos.searching.example">
  61. <title>Searching for videos</title>
  62. <programlisting language="php"><![CDATA[
  63. $yt = new Zend_Gdata_YouTube();
  64. $query = $yt->newVideoQuery();
  65. $query->videoQuery = 'cat';
  66. $query->startIndex = 10;
  67. $query->maxResults = 20;
  68. $query->orderBy = 'viewCount';
  69. echo $query->queryUrl . "\n";
  70. $videoFeed = $yt->getVideoFeed($query);
  71. foreach ($videoFeed as $videoEntry) {
  72. echo "---------VIDEO----------\n";
  73. echo "Title: " . $videoEntry->getVideoTitle() . "\n";
  74. echo "\nDescription:\n";
  75. echo $videoEntry->getVideoDescription();
  76. echo "\n\n\n";
  77. }
  78. ]]></programlisting>
  79. </example>
  80. <para>
  81. For more details on the different query parameters, please
  82. refer to the <ulink url="http://code.google.com/apis/youtube/reference.html#Searching_for_videos">
  83. Reference Guide</ulink>. The available helper functions in
  84. <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoQuery.html">
  85. <classname>Zend_Gdata_YouTube_VideoQuery</classname></ulink> for each of these parameters are
  86. described in more detail in the <ulink url="http://code.google.com/apis/youtube/developers_guide_php.html#SearchingVideos">PHP Developer's Guide</ulink>.
  87. </para>
  88. </sect3>
  89. <sect3 id="zend.gdata.youtube.videos.searchingcategories">
  90. <title>Searching for videos by categories and tags/keywords</title>
  91. <para>
  92. Searching for videos in specific categories is done by
  93. generating a <ulink url="http://code.google.com/apis/youtube/reference.html#Category_search">
  94. specially formatted <acronym>URL</acronym></ulink>. For example, to search for
  95. comedy videos which contain the keyword dog:
  96. </para>
  97. <example id="zend.gdata.youtube.videos.searchingcategories.example">
  98. <title>Searching for videos in specific categories</title>
  99. <programlisting language="php"><![CDATA[
  100. $yt = new Zend_Gdata_YouTube();
  101. $query = $yt->newVideoQuery();
  102. $query->category = 'Comedy/dog';
  103. echo $query->queryUrl . "\n";
  104. $videoFeed = $yt->getVideoFeed($query);
  105. ]]></programlisting>
  106. </example>
  107. </sect3>
  108. <sect3 id="zend.gdata.youtube.videos.standard">
  109. <title>Retrieving standard feeds</title>
  110. <para>
  111. The YouTube Data <acronym>API</acronym> has a number of
  112. <ulink url="http://code.google.com/apis/youtube/reference.html#Standard_feeds">
  113. standard feeds</ulink>. These standard feeds can be retrieved
  114. as <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoFeed.html">Zend_Gdata_YouTube_VideoFeed</ulink> objects using the specified
  115. <acronym>URL</acronym>s, using the predefined constants within the <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html">Zend_Gdata_YouTube</ulink> class
  116. (Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI for example) or
  117. using the predefined helper methods (see code listing below).
  118. </para>
  119. <para>
  120. To retrieve the top rated videos using the helper method:
  121. </para>
  122. <example id="zend.gdata.youtube.videos.standard.example-1">
  123. <title>Retrieving a standard video feed</title>
  124. <programlisting language="php"><![CDATA[
  125. $yt = new Zend_Gdata_YouTube();
  126. $videoFeed = $yt->getTopRatedVideoFeed();
  127. ]]></programlisting>
  128. </example>
  129. <para>
  130. There are also query parameters to specify the time period
  131. over which the standard feed is computed.
  132. </para>
  133. <para>
  134. For example, to retrieve the top rated videos for today:
  135. </para>
  136. <example id="zend.gdata.youtube.videos.standard.example-2">
  137. <title>Using a Zend_Gdata_YouTube_VideoQuery to Retrieve Videos</title>
  138. <programlisting language="php"><![CDATA[
  139. $yt = new Zend_Gdata_YouTube();
  140. $query = $yt->newVideoQuery();
  141. $query->setTime('today');
  142. $videoFeed = $yt->getTopRatedVideoFeed($query);
  143. ]]></programlisting>
  144. </example>
  145. <para>
  146. Alternatively, you could just retrieve the feed using the
  147. <acronym>URL</acronym>:
  148. </para>
  149. <example id="zend.gdata.youtube.videos.standard.example-3">
  150. <title>Retrieving a video feed by URL</title>
  151. <programlisting language="php"><![CDATA[
  152. $yt = new Zend_Gdata_YouTube();
  153. $url = 'http://gdata.youtube.com/feeds/standardfeeds/top_rated?time=today'
  154. $videoFeed = $yt->getVideoFeed($url);
  155. ]]></programlisting>
  156. </example>
  157. </sect3>
  158. <sect3 id="zend.gdata.youtube.videos.user">
  159. <title>Retrieving videos uploaded by a user</title>
  160. <para>
  161. You can retrieve a list of videos uploaded by a particular user
  162. using a simple helper method. This example retrieves videos
  163. uploaded by the user 'liz'.
  164. </para>
  165. <example id="zend.gdata.youtube.videos.user.example">
  166. <title>Retrieving videos uploaded by a specific user</title>
  167. <programlisting language="php"><![CDATA[
  168. $yt = new Zend_Gdata_YouTube();
  169. $videoFeed = $yt->getUserUploads('liz');
  170. ]]></programlisting>
  171. </example>
  172. </sect3>
  173. <sect3 id="zend.gdata.youtube.videos.favorites">
  174. <title>Retrieving videos favorited by a user</title>
  175. <para>
  176. You can retrieve a list of a user's favorite videos
  177. using a simple helper method. This example retrieves videos
  178. favorited by the user 'liz'.
  179. </para>
  180. <example id="zend.gdata.youtube.videos.favorites.example">
  181. <title>Retrieving a user's favorite videos</title>
  182. <programlisting language="php"><![CDATA[
  183. $yt = new Zend_Gdata_YouTube();
  184. $videoFeed = $yt->getUserFavorites('liz');
  185. ]]></programlisting>
  186. </example>
  187. </sect3>
  188. <sect3 id="zend.gdata.youtube.videos.responses">
  189. <title>Retrieving video responses for a video</title>
  190. <para>
  191. You can retrieve a list of a video's video responses
  192. using a simple helper method. This example retrieves video
  193. response for a video with the ID 'abc123813abc'.
  194. </para>
  195. <example id="zend.gdata.youtube.videos.responses.example">
  196. <title>Retrieving a feed of video responses</title>
  197. <programlisting language="php"><![CDATA[
  198. $yt = new Zend_Gdata_YouTube();
  199. $videoFeed = $yt->getVideoResponseFeed('abc123813abc');
  200. ]]></programlisting>
  201. </example>
  202. </sect3>
  203. </sect2>
  204. <sect2 id="zend.gdata.youtube.comments">
  205. <title>Retrieving video comments</title>
  206. <para>
  207. The comments for each YouTube video can be retrieved in
  208. several ways. To retrieve the comments for the video with
  209. the ID 'abc123813abc', use the following code:
  210. </para>
  211. <example id="zend.gdata.youtube.videos.comments.example-1">
  212. <title>Retrieving a feed of video comments from a video ID</title>
  213. <programlisting language="php"><![CDATA[
  214. $yt = new Zend_Gdata_YouTube();
  215. $commentFeed = $yt->getVideoCommentFeed('abc123813abc');
  216. foreach ($commentFeed as $commentEntry) {
  217. echo $commentEntry->title->text . "\n";
  218. echo $commentEntry->content->text . "\n\n\n";
  219. }
  220. ]]></programlisting>
  221. </example>
  222. <para>
  223. Comments can also be retrieved for a video if you have
  224. a copy of the <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html">Zend_Gdata_YouTube_VideoEntry</ulink> object:
  225. </para>
  226. <example id="zend.gdata.youtube.videos.comments.example-2">
  227. <title>Retrieving a Feed of Video Comments from a Zend_Gdata_YouTube_VideoEntry</title>
  228. <programlisting language="php"><![CDATA[
  229. $yt = new Zend_Gdata_YouTube();
  230. $videoEntry = $yt->getVideoEntry('abc123813abc');
  231. // we don't know the video ID in this example, but we do have the URL
  232. $commentFeed = $yt->getVideoCommentFeed(null,
  233. $videoEntry->comments->href);
  234. ]]></programlisting>
  235. </example>
  236. </sect2>
  237. <sect2 id="zend.gdata.youtube.playlists">
  238. <title>Retrieving playlist feeds</title>
  239. <para>
  240. The YouTube Data <acronym>API</acronym> provides information about users, including
  241. profiles, playlists, subscriptions, and more.
  242. </para>
  243. <sect3 id="zend.gdata.youtube.playlists.user">
  244. <title>Retrieving the playlists of a user</title>
  245. <para>
  246. The library provides a helper method to retrieve
  247. the playlists associated with a given user. To retrieve the
  248. playlists for the user 'liz':
  249. </para>
  250. <example id="zend.gdata.youtube.playlists.user.example">
  251. <title>Retrieving the playlists of a user</title>
  252. <programlisting language="php"><![CDATA[
  253. $yt = new Zend_Gdata_YouTube();
  254. $playlistListFeed = $yt->getPlaylistListFeed('liz');
  255. foreach ($playlistListFeed as $playlistEntry) {
  256. echo $playlistEntry->title->text . "\n";
  257. echo $playlistEntry->description->text . "\n";
  258. echo $playlistEntry->getPlaylistVideoFeedUrl() . "\n\n\n";
  259. }
  260. ]]></programlisting>
  261. </example>
  262. </sect3>
  263. <sect3 id="zend.gdata.youtube.playlists.special">
  264. <title>Retrieving a specific playlist</title>
  265. <para>
  266. The library provides a helper method to retrieve
  267. the videos associated with a given playlist. To retrieve the
  268. playlists for a specific playlist entry:
  269. </para>
  270. <example id="zend.gdata.youtube.playlists.special.example">
  271. <title>Retrieving a specific playlist</title>
  272. <programlisting language="php"><![CDATA[
  273. $feedUrl = $playlistEntry->getPlaylistVideoFeedUrl();
  274. $playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
  275. ]]></programlisting>
  276. </example>
  277. </sect3>
  278. </sect2>
  279. <sect2 id="zend.gdata.youtube.subscriptions">
  280. <title>Retrieving a list of a user's subscriptions</title>
  281. <para>
  282. A user can have several types of subscriptions: channel
  283. subscription, tag subscription, or favorites subscription.
  284. A <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_SubscriptionEntry.html">Zend_Gdata_YouTube_SubscriptionEntry</ulink> is used to represent
  285. individual subscriptions.
  286. </para>
  287. <para>
  288. To retrieve all subscriptions for the user 'liz':
  289. </para>
  290. <example id="zend.gdata.youtube.subscriptions.example">
  291. <title>Retrieving all subscriptions for a user</title>
  292. <programlisting language="php"><![CDATA[
  293. $yt = new Zend_Gdata_YouTube();
  294. $subscriptionFeed = $yt->getSubscriptionFeed('liz');
  295. foreach ($subscriptionFeed as $subscriptionEntry) {
  296. echo $subscriptionEntry->title->text . "\n";
  297. }
  298. ]]></programlisting>
  299. </example>
  300. </sect2>
  301. <sect2 id="zend.gdata.youtube.profile">
  302. <title>Retrieving a user's profile</title>
  303. <para>
  304. You can retrieve the public profile information
  305. for any YouTube user. To retrieve the profile
  306. for the user 'liz':
  307. </para>
  308. <example id="zend.gdata.youtube.profile.example">
  309. <title>Retrieving a user's profile</title>
  310. <programlisting language="php"><![CDATA[
  311. $yt = new Zend_Gdata_YouTube();
  312. $userProfile = $yt->getUserProfile('liz');
  313. echo "username: " . $userProfile->username->text . "\n";
  314. echo "age: " . $userProfile->age->text . "\n";
  315. echo "hometown: " . $userProfile->hometown->text . "\n";
  316. ]]></programlisting>
  317. </example>
  318. </sect2>
  319. <sect2 id="zend.gdata.youtube.uploads">
  320. <title>Uploading Videos to YouTube</title>
  321. <para>
  322. Please make sure to review the diagrams in the
  323. <ulink url="http://code.google.com/apis/youtube/developers_guide_protocol.html#Process_Flows_for_Uploading_Videos">protocol guide</ulink> on code.google.com for a high-level
  324. overview of the upload process. Uploading videos can be done in one of
  325. two ways: either by uploading the video directly or by sending just the
  326. video meta-data and having a user upload the video through an HTML form.
  327. </para>
  328. <para>
  329. In order to upload a video directly, you must first construct a new
  330. <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html">Zend_Gdata_YouTube_VideoEntry</ulink> object and specify some required meta-data
  331. The following example shows uploading the Quicktime video "mytestmovie.mov"
  332. to YouTube with the following properties:
  333. </para>
  334. <table id="zend.gdata.youtube.uploads.metadata">
  335. <title>Metadata used in the code-sample below</title>
  336. <tgroup cols="2" align="left" colsep="1" rowsep="1">
  337. <thead>
  338. <row>
  339. <entry>Property</entry>
  340. <entry>Value</entry>
  341. </row>
  342. </thead>
  343. <tbody>
  344. <row>
  345. <entry>Title</entry>
  346. <entry>My Test Movie</entry>
  347. </row>
  348. <row>
  349. <entry>Category</entry>
  350. <entry>Autos</entry>
  351. </row>
  352. <row>
  353. <entry>Keywords</entry>
  354. <entry>cars, funny</entry>
  355. </row>
  356. <row>
  357. <entry>Description</entry>
  358. <entry>My description</entry>
  359. </row>
  360. <row>
  361. <entry>Filename</entry>
  362. <entry>mytestmovie.mov</entry>
  363. </row>
  364. <row>
  365. <entry>File <acronym>MIME</acronym> type</entry>
  366. <entry>video/quicktime</entry>
  367. </row>
  368. <row>
  369. <entry>Video private?</entry>
  370. <entry><constant>FALSE</constant></entry>
  371. </row>
  372. <row>
  373. <entry>Video location</entry>
  374. <entry>37, -122 (lat, long)</entry>
  375. </row>
  376. <row>
  377. <entry>Developer Tags</entry>
  378. <entry>mydevelopertag, anotherdevelopertag</entry>
  379. </row>
  380. </tbody>
  381. </tgroup>
  382. </table>
  383. <para>
  384. The code below creates a blank <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html">Zend_Gdata_YouTube_VideoEntry</ulink> to be uploaded.
  385. A <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html">Zend_Gdata_App_MediaFileSource</ulink> object is then used to hold the actual video file. Under the hood, the <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_Extension_MediaGroup.html">Zend_Gdata_YouTube_Extension_MediaGroup</ulink> object is used to hold all
  386. of the video's meta-data. Our helper methods detailed below allow you to
  387. just set the video meta-data without having to worry about the media group object.
  388. The $uploadUrl is the location where the new entry gets posted to.
  389. This can be specified either with the $userName of the
  390. currently authenticated user, or, alternatively, you can simply use the
  391. string 'default' to refer to the currently authenticated user.
  392. </para>
  393. <example id="zend.gdata.youtube.uploads.example">
  394. <title>Uploading a video</title>
  395. <programlisting language="php"><![CDATA[
  396. $yt = new Zend_Gdata_YouTube($httpClient);
  397. $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  398. $filesource = $yt->newMediaFileSource('mytestmovie.mov');
  399. $filesource->setContentType('video/quicktime');
  400. $filesource->setSlug('mytestmovie.mov');
  401. $myVideoEntry->setMediaSource($filesource);
  402. $myVideoEntry->setVideoTitle('My Test Movie');
  403. $myVideoEntry->setVideoDescription('My Test Movie');
  404. // Note that category must be a valid YouTube category !
  405. $myVideoEntry->setVideoCategory('Comedy');
  406. // Set keywords, note that this must be a comma separated string
  407. // and that each keyword cannot contain whitespace
  408. $myVideoEntry->SetVideoTags('cars, funny');
  409. // Optionally set some developer tags
  410. $myVideoEntry->setVideoDeveloperTags(array('mydevelopertag',
  411. 'anotherdevelopertag'));
  412. // Optionally set the video's location
  413. $yt->registerPackage('Zend_Gdata_Geo');
  414. $yt->registerPackage('Zend_Gdata_Geo_Extension');
  415. $where = $yt->newGeoRssWhere();
  416. $position = $yt->newGmlPos('37.0 -122.0');
  417. $where->point = $yt->newGmlPoint($position);
  418. $myVideoEntry->setWhere($where);
  419. // Upload URI for the currently authenticated user
  420. $uploadUrl =
  421. 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
  422. // Try to upload the video, catching a Zend_Gdata_App_HttpException
  423. // if availableor just a regular Zend_Gdata_App_Exception
  424. try {
  425. $newEntry = $yt->insertEntry($myVideoEntry,
  426. $uploadUrl,
  427. 'Zend_Gdata_YouTube_VideoEntry');
  428. } catch (Zend_Gdata_App_HttpException $httpException) {
  429. echo $httpException->getRawResponseBody();
  430. } catch (Zend_Gdata_App_Exception $e) {
  431. echo $e->getMessage();
  432. }
  433. ]]></programlisting>
  434. </example>
  435. <para>
  436. To upload a video as private, simply use: $myVideoEntry->setVideoPrivate(); prior to
  437. performing the upload. $videoEntry->isVideoPrivate() can be used to check whether a video
  438. entry is private or not.
  439. </para>
  440. </sect2>
  441. <sect2 id="zend.gdata.youtube.uploads.browser">
  442. <title>Browser-based upload</title>
  443. <para>
  444. Browser-based uploading is performed almost identically to direct uploading,
  445. except that you do not attach a <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html">Zend_Gdata_App_MediaFileSource</ulink> object to
  446. the <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html">Zend_Gdata_YouTube_VideoEntry</ulink> you are constructing. Instead you simply
  447. submit all of your video's meta-data to receive back a token element
  448. which can be used to construct an HTML upload form.
  449. </para>
  450. <example id="zend.gdata.youtube.uploads.browser.example-1">
  451. <title>Browser-based upload</title>
  452. <programlisting language="php"><![CDATA[
  453. $yt = new Zend_Gdata_YouTube($httpClient);
  454. $myVideoEntry= new Zend_Gdata_YouTube_VideoEntry();
  455. $myVideoEntry->setVideoTitle('My Test Movie');
  456. $myVideoEntry->setVideoDescription('My Test Movie');
  457. // Note that category must be a valid YouTube category
  458. $myVideoEntry->setVideoCategory('Comedy');
  459. $myVideoEntry->SetVideoTags('cars, funny');
  460. $tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
  461. $tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
  462. $tokenValue = $tokenArray['token'];
  463. $postUrl = $tokenArray['url'];
  464. ]]></programlisting>
  465. </example>
  466. <para>
  467. The above code prints out a link and a token that is used to construct an
  468. HTML form to display in the user's browser. A simple example form is shown
  469. below with $tokenValue representing the content of the returned token element,
  470. as shown being retrieved from $myVideoEntry above. In order for the user
  471. to be redirected to your website after submitting the form, make sure to
  472. append a $nextUrl parameter to the $postUrl above, which functions in the
  473. same way as the $next parameter of an AuthSub link. The only difference is
  474. that here, instead of a single-use token, a status and an id variable are
  475. returned in the <acronym>URL</acronym>.
  476. </para>
  477. <example id="zend.gdata.youtube.uploads.browser.example-2">
  478. <title>Browser-based upload: Creating the HTML form</title>
  479. <programlisting language="php"><![CDATA[
  480. // place to redirect user after upload
  481. $nextUrl = 'http://mysite.com/youtube_uploads';
  482. $form = '<form action="'. $postUrl .'?nexturl='. $nextUrl .
  483. '" method="post" enctype="multipart/form-data">'.
  484. '<input name="file" type="file"/>'.
  485. '<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
  486. '<input value="Upload Video File" type="submit" />'.
  487. '</form>';
  488. ]]></programlisting>
  489. </example>
  490. </sect2>
  491. <sect2 id="zend.gdata.youtube.uploads.status">
  492. <title>Checking upload status</title>
  493. <para>
  494. After uploading a video, it will immediately be visible in an
  495. authenticated user's uploads feed. However, it will not be public on
  496. the site until it has been processed. Videos that have been rejected or
  497. failed to upload successfully will also only be in the authenticated
  498. user's uploads feed. The following code checks the status of a
  499. <ulink url="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html">Zend_Gdata_YouTube_VideoEntry</ulink> to see if it is not live yet or if it has been rejected.
  500. </para>
  501. <example id="zend.gdata.youtube.uploads.status.example">
  502. <title>Checking video upload status</title>
  503. <programlisting language="php"><![CDATA[
  504. try {
  505. $control = $videoEntry->getControl();
  506. } catch (Zend_Gdata_App_Exception $e) {
  507. echo $e->getMessage();
  508. }
  509. if ($control instanceof Zend_Gdata_App_Extension_Control) {
  510. if ($control->getDraft() != null &&
  511. $control->getDraft()->getText() == 'yes') {
  512. $state = $videoEntry->getVideoState();
  513. if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
  514. print 'Upload status: '
  515. . $state->getName()
  516. .' '. $state->getText();
  517. } else {
  518. print 'Not able to retrieve the video status information'
  519. .' yet. ' . "Please try again shortly.\n";
  520. }
  521. }
  522. }
  523. ]]></programlisting>
  524. </example>
  525. </sect2>
  526. <sect2 id="zend.gdata.youtube.other">
  527. <title>Other Functions</title>
  528. <para>
  529. In addition to the functionality described above, the YouTube <acronym>API</acronym>
  530. contains many other functions that allow you to modify video meta-data,
  531. delete video entries and use the full range of community features on the site.
  532. Some of the community features that can be modified through the <acronym>API</acronym> include:
  533. ratings, comments, playlists, subscriptions, user profiles, contacts and messages.
  534. </para>
  535. <para>
  536. Please refer to the full documentation available in the
  537. <ulink url="http://code.google.com/apis/youtube/developers_guide_php.html">PHP Developer's Guide</ulink> on code.google.com.
  538. </para>
  539. </sect2>
  540. </sect1>