Zend_Gdata_YouTube.xml 28 KB

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