1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Using the YouTube Data API - Zend Framework Manual</title>
</head>
<body>
<table width="100%">
<tr valign="top">
<td width="85%">
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="zend.gdata.photos.html">Using Picasa Web Albums</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></div>
</td>
</tr>
</table>
<hr />
<div id="zend.gdata.youtube" class="section"><div class="info"><h1 class="title">Using the YouTube Data API</h1></div>
<p class="para">
The YouTube Data <acronym class="acronym">API</acronym> 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.
</p>
<p class="para">
For more information on the YouTube Data <acronym class="acronym">API</acronym>, please refer
to the official <a href="http://code.google.com/apis/youtube/developers_guide_php.html" class="link external">» <acronym class="acronym">PHP</acronym>
Developer's Guide</a> on code.google.com.
</p>
<div class="section" id="zend.gdata.youtube.authentication" name="zend.gdata.youtube.authentication"><div class="info"><h1 class="title">Authentication</h1></div>
<p class="para">
The YouTube Data <acronym class="acronym">API</acronym> 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 <a href="http://code.google.com/apis/youtube/developers_guide_php.html#Authentication" class="link external">» Authentication
section in the <acronym class="acronym">PHP</acronym> Developer's Guide</a> for more detail.
</p>
</div>
<div class="section" id="zend.gdata.youtube.developer_key" name="zend.gdata.youtube.developer_key"><div class="info"><h1 class="title">Developer Keys and Client ID</h1></div>
<p class="para">
A developer key identifies the YouTube developer that is submitting
an <acronym class="acronym">API</acronym> request. A client ID identifies your application for logging
and debugging purposes. Please visit <a href="http://code.google.com/apis/youtube/dashboard/" class="link external">» http://code.google.com/apis/youtube/dashboard/</a>
to obtain a developer key and client ID. The example below demonstrates how to pass the
developer key and client ID to the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html" class="link external">» Zend_Gdata_YouTube</a>
service object.
</p>
<div class="example"><div class="info"><p><b>Example #1 Passing a Developer Key and ClientID to Zend_Gdata_YouTube</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$httpClient</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$applicationId</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$clientId</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$developerKey</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.videos" name="zend.gdata.youtube.videos"><div class="info"><h1 class="title">Retrieving public video feeds</h1></div>
<p class="para">
The YouTube Data <acronym class="acronym">API</acronym> 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 <a href="http://code.google.com/apis/youtube/reference.html#Video_Feeds" class="link external">» YouTube
<acronym class="acronym">API</acronym> reference guide</a> for a detailed list of available
feeds.
</p>
<div class="section" id="zend.gdata.youtube.videos.searching" name="zend.gdata.youtube.videos.searching"><div class="info"><h1 class="title">Searching for videos by metadata</h1></div>
<p class="para">
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.
</p>
<div class="example"><div class="info"><p><b>Example #2 Searching for videos</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newVideoQuery</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">videoQuery</span> = <span style="color: #ff0000;">'cat'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">startIndex</span> = <span style="color: #cc66cc;">10</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">maxResults</span> = <span style="color: #cc66cc;">20</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">orderBy</span> = <span style="color: #ff0000;">'viewCount'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$query</span>-><span style="color: #006600;">queryUrl</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$videoFeed</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$videoEntry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"---------VIDEO----------<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"Title: "</span> . <span style="color: #0000ff;">$videoEntry</span>-><span style="color: #006600;">getVideoTitle</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>Description:<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$videoEntry</span>-><span style="color: #006600;">getVideoDescription</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
<p class="para">
For more details on the different query parameters, please refer to the <a href="http://code.google.com/apis/youtube/reference.html#Searching_for_videos" class="link external">»
Reference Guide</a>. The available helper functions in <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoQuery.html" class="link external">» <span class="classname">Zend_Gdata_YouTube_VideoQuery</span></a>
for each of these parameters are described in more detail in the <a href="http://code.google.com/apis/youtube/developers_guide_php.html#SearchingVideos" class="link external">» PHP
Developer's Guide</a>.
</p>
</div>
<div class="section" id="zend.gdata.youtube.videos.searchingcategories" name="zend.gdata.youtube.videos.searchingcategories"><div class="info"><h1 class="title">Searching for videos by categories and tags/keywords</h1></div>
<p class="para">
Searching for videos in specific categories is done by generating a <a href="http://code.google.com/apis/youtube/reference.html#Category_search" class="link external">» specially
formatted <acronym class="acronym">URL</acronym></a>. For example, to search for
comedy videos which contain the keyword dog:
</p>
<div class="example"><div class="info"><p><b>Example #3 Searching for videos in specific categories</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newVideoQuery</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">category</span> = <span style="color: #ff0000;">'Comedy/dog'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$query</span>-><span style="color: #006600;">queryUrl</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.videos.standard" name="zend.gdata.youtube.videos.standard"><div class="info"><h1 class="title">Retrieving standard feeds</h1></div>
<p class="para">
The YouTube Data <acronym class="acronym">API</acronym> has a number of <a href="http://code.google.com/apis/youtube/reference.html#Standard_feeds" class="link external">» standard
feeds</a>. These standard feeds can be retrieved as <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoFeed.html" class="link external">» Zend_Gdata_YouTube_VideoFeed</a>
objects using the specified <acronym class="acronym">URL</acronym>s, using the predefined constants
within the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube.html" class="link external">» Zend_Gdata_YouTube</a>
class (Zend_Gdata_YouTube::STANDARD_TOP_RATED_URI for example) or
using the predefined helper methods (see code listing below).
</p>
<p class="para">
To retrieve the top rated videos using the helper method:
</p>
<div class="example"><div class="info"><p><b>Example #4 Retrieving a standard video feed</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getTopRatedVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
<p class="para">
There are also query parameters to specify the time period
over which the standard feed is computed.
</p>
<p class="para">
For example, to retrieve the top rated videos for today:
</p>
<div class="example"><div class="info"><p><b>Example #5 Using a Zend_Gdata_YouTube_VideoQuery to Retrieve Videos</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newVideoQuery</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$query</span>-><span style="color: #006600;">setTime</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'today'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getTopRatedVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$query</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
<p class="para">
Alternatively, you could just retrieve the feed using the
<acronym class="acronym">URL</acronym>:
</p>
<div class="example"><div class="info"><p><b>Example #6 Retrieving a video feed by URL</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$url</span> = <span style="color: #ff0000;">'http://gdata.youtube.com/feeds/standardfeeds/top_rated?time=today'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$url</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.videos.user" name="zend.gdata.youtube.videos.user"><div class="info"><h1 class="title">Retrieving videos uploaded by a user</h1></div>
<p class="para">
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'.
</p>
<div class="example"><div class="info"><p><b>Example #7 Retrieving videos uploaded by a specific user</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getUserUploads</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'liz'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.videos.favorites" name="zend.gdata.youtube.videos.favorites"><div class="info"><h1 class="title">Retrieving videos favorited by a user</h1></div>
<p class="para">
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'.
</p>
<div class="example"><div class="info"><p><b>Example #8 Retrieving a user's favorite videos</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getUserFavorites</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'liz'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.videos.responses" name="zend.gdata.youtube.videos.responses"><div class="info"><h1 class="title">Retrieving video responses for a video</h1></div>
<p class="para">
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'.
</p>
<div class="example"><div class="info"><p><b>Example #9 Retrieving a feed of video responses</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoResponseFeed</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'abc123813abc'</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.comments" name="zend.gdata.youtube.comments"><div class="info"><h1 class="title">Retrieving video comments</h1></div>
<p class="para">
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:
</p>
<div class="example"><div class="info"><p><b>Example #10 Retrieving a feed of video comments from a video ID</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$commentFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoCommentFeed</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'abc123813abc'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$commentFeed</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$commentEntry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$commentEntry</span>-><span style="color: #006600;">title</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$commentEntry</span>-><span style="color: #006600;">content</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
<p class="para">
Comments can also be retrieved for a video if you have a copy of the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">» Zend_Gdata_YouTube_VideoEntry</a>
object:
</p>
<div class="example"><div class="info"><p><b>Example #11 Retrieving a Feed of Video Comments from a Zend_Gdata_YouTube_VideoEntry</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$videoEntry</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoEntry</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'abc123813abc'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// we don't know the video ID in this example, but we do have the URL</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$commentFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getVideoCommentFeed</span><span style="color: #66cc66;">(</span><span style="color: #000000; font-weight: bold;">null</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$videoEntry</span>-><span style="color: #006600;">comments</span>-><span style="color: #006600;">href</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.playlists" name="zend.gdata.youtube.playlists"><div class="info"><h1 class="title">Retrieving playlist feeds</h1></div>
<p class="para">
The YouTube Data <acronym class="acronym">API</acronym> provides information about users, including
profiles, playlists, subscriptions, and more.
</p>
<div class="section" id="zend.gdata.youtube.playlists.user" name="zend.gdata.youtube.playlists.user"><div class="info"><h1 class="title">Retrieving the playlists of a user</h1></div>
<p class="para">
The library provides a helper method to retrieve
the playlists associated with a given user. To retrieve the
playlists for the user 'liz':
</p>
<div class="example"><div class="info"><p><b>Example #12 Retrieving the playlists of a user</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$playlistListFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getPlaylistListFeed</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'liz'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$playlistListFeed</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$playlistEntry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$playlistEntry</span>-><span style="color: #006600;">title</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$playlistEntry</span>-><span style="color: #006600;">description</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$playlistEntry</span>-><span style="color: #006600;">getPlaylistVideoFeedUrl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.playlists.special" name="zend.gdata.youtube.playlists.special"><div class="info"><h1 class="title">Retrieving a specific playlist</h1></div>
<p class="para">
The library provides a helper method to retrieve
the videos associated with a given playlist. To retrieve the
playlists for a specific playlist entry:
</p>
<div class="example"><div class="info"><p><b>Example #13 Retrieving a specific playlist</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$feedUrl</span> = <span style="color: #0000ff;">$playlistEntry</span>-><span style="color: #006600;">getPlaylistVideoFeedUrl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$playlistVideoFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getPlaylistVideoFeed</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$feedUrl</span><span style="color: #66cc66;">)</span>;</div></li></ol></div></div></div>
</div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.subscriptions" name="zend.gdata.youtube.subscriptions"><div class="info"><h1 class="title">Retrieving a list of a user's subscriptions</h1></div>
<p class="para">
A user can have several types of subscriptions: channel
subscription, tag subscription, or favorites subscription. A <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_SubscriptionEntry.html" class="link external">» Zend_Gdata_YouTube_SubscriptionEntry</a>
is used to represent individual subscriptions.
</p>
<p class="para">
To retrieve all subscriptions for the user 'liz':
</p>
<div class="example"><div class="info"><p><b>Example #14 Retrieving all subscriptions for a user</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$subscriptionFeed</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getSubscriptionFeed</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'liz'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$subscriptionFeed</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$subscriptionEntry</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$subscriptionEntry</span>-><span style="color: #006600;">title</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.profile" name="zend.gdata.youtube.profile"><div class="info"><h1 class="title">Retrieving a user's profile</h1></div>
<p class="para">
You can retrieve the public profile information
for any YouTube user. To retrieve the profile
for the user 'liz':
</p>
<div class="example"><div class="info"><p><b>Example #15 Retrieving a user's profile</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$userProfile</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getUserProfile</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'liz'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"username: "</span> . <span style="color: #0000ff;">$userProfile</span>-><span style="color: #006600;">username</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"age: "</span> . <span style="color: #0000ff;">$userProfile</span>-><span style="color: #006600;">age</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #ff0000;">"hometown: "</span> . <span style="color: #0000ff;">$userProfile</span>-><span style="color: #006600;">hometown</span>-><span style="color: #006600;">text</span> . <span style="color: #ff0000;">"<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.uploads" name="zend.gdata.youtube.uploads"><div class="info"><h1 class="title">Uploading Videos to YouTube</h1></div>
<p class="para">
Please make sure to review the diagrams in the <a href="http://code.google.com/apis/youtube/developers_guide_protocol.html#Process_Flows_for_Uploading_Videos" class="link external">» protocol
guide</a> 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 <acronym class="acronym">HTML</acronym> form.
</p>
<p class="para">
In order to upload a video directly, you must first construct a new <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">» Zend_Gdata_YouTube_VideoEntry</a>
object and specify some required meta-data. The following example shows uploading the
Quicktime video "mytestmovie.mov" to YouTube with the following properties:
</p>
<table class="doctable table"><div class="info"><caption><b>Metadata used in the code-sample below</b></caption></div>
<thead valign="middle">
<tr valign="middle">
<th>Property</th>
<th>Value</th>
</tr>
</thead>
<tbody valign="middle" class="tbody">
<tr valign="middle">
<td align="left">Title</td>
<td align="left">My Test Movie</td>
</tr>
<tr valign="middle">
<td align="left">Category</td>
<td align="left">Autos</td>
</tr>
<tr valign="middle">
<td align="left">Keywords</td>
<td align="left">cars, funny</td>
</tr>
<tr valign="middle">
<td align="left">Description</td>
<td align="left">My description</td>
</tr>
<tr valign="middle">
<td align="left">Filename</td>
<td align="left">mytestmovie.mov</td>
</tr>
<tr valign="middle">
<td align="left">File <acronym class="acronym">MIME</acronym> type</td>
<td align="left">video/quicktime</td>
</tr>
<tr valign="middle">
<td align="left">Video private?</td>
<td align="left"><b><tt>FALSE</tt></b></td>
</tr>
<tr valign="middle">
<td align="left">Video location</td>
<td align="left">37, -122 (lat, long)</td>
</tr>
<tr valign="middle">
<td align="left">Developer Tags</td>
<td align="left">mydevelopertag, anotherdevelopertag</td>
</tr>
</tbody>
</table>
<p class="para">
The code below creates a blank <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">» Zend_Gdata_YouTube_VideoEntry</a>
to be uploaded. A <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html" class="link external">» Zend_Gdata_App_MediaFileSource</a>
object is then used to hold the actual video file. Under the hood, the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_Extension_MediaGroup.html" class="link external">» Zend_Gdata_YouTube_Extension_MediaGroup</a>
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.
</p>
<div class="example"><div class="info"><p><b>Example #16 Uploading a video</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$httpClient</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube_VideoEntry<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$filesource</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newMediaFileSource</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'mytestmovie.mov'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$filesource</span>-><span style="color: #006600;">setContentType</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'video/quicktime'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$filesource</span>-><span style="color: #006600;">setSlug</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'mytestmovie.mov'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setMediaSource</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$filesource</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoTitle</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'My Test Movie'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoDescription</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'My Test Movie'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Note that category must be a valid YouTube category !</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoCategory</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Comedy'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Set keywords, note that this must be a comma separated string</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// and that each keyword cannot contain whitespace</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">SetVideoTags</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'cars, funny'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Optionally set some developer tags</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoDeveloperTags</span><span style="color: #66cc66;">(</span><a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'mydevelopertag'</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'anotherdevelopertag'</span><span style="color: #66cc66;">)</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Optionally set the video's location</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">registerPackage</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Zend_Gdata_Geo'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">registerPackage</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Zend_Gdata_Geo_Extension'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$where</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newGeoRssWhere</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$position</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newGmlPos</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'37.0 -122.0'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$where</span>-><span style="color: #006600;">point</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">newGmlPoint</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$position</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setWhere</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$where</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Upload URI for the currently authenticated user</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$uploadUrl</span> =</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'http://uploads.gdata.youtube.com/feeds/users/default/uploads'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Try to upload the video, catching a Zend_Gdata_App_HttpException</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// if availableor just a regular Zend_Gdata_App_Exception</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">try <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$newEntry</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">insertEntry</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$myVideoEntry</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$uploadUrl</span>,</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'Zend_Gdata_YouTube_VideoEntry'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Zend_Gdata_App_HttpException <span style="color: #0000ff;">$httpException</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$httpException</span>-><span style="color: #006600;">getRawResponseBody</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Zend_Gdata_App_Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$e</span>-><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
<p class="para">
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.
</p>
</div>
<div class="section" id="zend.gdata.youtube.uploads.browser" name="zend.gdata.youtube.uploads.browser"><div class="info"><h1 class="title">Browser-based upload</h1></div>
<p class="para">
Browser-based uploading is performed almost identically to direct uploading,
except that you do not attach a <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_App_MediaFileSource.html" class="link external">» Zend_Gdata_App_MediaFileSource</a>
object to the <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">» Zend_Gdata_YouTube_VideoEntry</a>
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 <acronym class="acronym">HTML</acronym> upload
form.
</p>
<div class="example"><div class="info"><p><b>Example #17 Browser-based upload</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$yt</span> = <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube<span style="color: #66cc66;">(</span><span style="color: #0000ff;">$httpClient</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>= <span style="color: #000000; font-weight: bold;">new</span> Zend_Gdata_YouTube_VideoEntry<span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoTitle</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'My Test Movie'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoDescription</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'My Test Movie'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Note that category must be a valid YouTube category</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">setVideoCategory</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'Comedy'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$myVideoEntry</span>-><span style="color: #006600;">SetVideoTags</span><span style="color: #66cc66;">(</span><span style="color: #ff0000;">'cars, funny'</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$tokenHandlerUrl</span> = <span style="color: #ff0000;">'http://gdata.youtube.com/action/GetUploadToken'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$tokenArray</span> = <span style="color: #0000ff;">$yt</span>-><span style="color: #006600;">getFormUploadToken</span><span style="color: #66cc66;">(</span><span style="color: #0000ff;">$myVideoEntry</span>, <span style="color: #0000ff;">$tokenHandlerUrl</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$tokenValue</span> = <span style="color: #0000ff;">$tokenArray</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'token'</span><span style="color: #66cc66;">]</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$postUrl</span> = <span style="color: #0000ff;">$tokenArray</span><span style="color: #66cc66;">[</span><span style="color: #ff0000;">'url'</span><span style="color: #66cc66;">]</span>;</div></li></ol></div></div></div>
</div>
<p class="para">
The above code prints out a link and a token that is used to construct an
<acronym class="acronym">HTML</acronym> 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 <acronym class="acronym">URL</acronym>.
</p>
<div class="example"><div class="info"><p><b>Example #18 Browser-based upload: Creating the HTML form</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// place to redirect user after upload</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$nextUrl</span> = <span style="color: #ff0000;">'http://mysite.com/youtube_uploads'</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0000ff;">$form</span> = <span style="color: #ff0000;">'<form action="'</span>. <span style="color: #0000ff;">$postUrl</span> .<span style="color: #ff0000;">'?nexturl='</span>. <span style="color: #0000ff;">$nextUrl</span> .</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'" method="post" enctype="multipart/form-data">'</span>.</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'<input name="file" type="file"/>'</span>.</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'<input name="token" type="hidden" value="'</span>. <span style="color: #0000ff;">$tokenValue</span> .<span style="color: #ff0000;">'"/>'</span>.</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'<input value="Upload Video File" type="submit" />'</span>.</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #ff0000;">'</form>'</span>;</div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.uploads.status" name="zend.gdata.youtube.uploads.status"><div class="info"><h1 class="title">Checking upload status</h1></div>
<p class="para">
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 <a href="http://framework.zend.com/apidoc/core/Zend_Gdata/Zend_Gdata_YouTube_VideoEntry.html" class="link external">» Zend_Gdata_YouTube_VideoEntry</a>
to see if it is not live yet or if it has been rejected.
</p>
<div class="example"><div class="info"><p><b>Example #19 Checking video upload status</b></p></div>
<div class="programlisting php"><div class="phpcode"><div class="php" style="font-family: monospace;"><ol><li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">try <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$control</span> = <span style="color: #0000ff;">$videoEntry</span>-><span style="color: #006600;">getControl</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span> catch <span style="color: #66cc66;">(</span>Zend_Gdata_App_Exception <span style="color: #0000ff;">$e</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> <span style="color: #0000ff;">$e</span>-><span style="color: #006600;">getMessage</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$control</span> instanceof Zend_Gdata_App_Extension_Control<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$control</span>-><span style="color: #006600;">getDraft</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> != <span style="color: #000000; font-weight: bold;">null</span> &&</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$control</span>-><span style="color: #006600;">getDraft</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>-><span style="color: #006600;">getText</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span> == <span style="color: #ff0000;">'yes'</span><span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #0000ff;">$state</span> = <span style="color: #0000ff;">$videoEntry</span>-><span style="color: #006600;">getVideoState</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> </div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">(</span><span style="color: #0000ff;">$state</span> instanceof Zend_Gdata_YouTube_Extension_State<span style="color: #66cc66;">)</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">'Upload status: '</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> . <span style="color: #0000ff;">$state</span>-><span style="color: #006600;">getName</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> .<span style="color: #ff0000;">' '</span>. <span style="color: #0000ff;">$state</span>-><span style="color: #006600;">getText</span><span style="color: #66cc66;">(</span><span style="color: #66cc66;">)</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #66cc66;">}</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">{</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <a href="http://www.php.net/print"><span style="color: #000066;">print</span></a> <span style="color: #ff0000;">'Not able to retrieve the video status information'</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> .<span style="color: #ff0000;">' yet. '</span> . <span style="color: #ff0000;">"Please try again shortly.<span style="color: #000099; font-weight: bold;">\n</span>"</span>;</div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"> <span style="color: #66cc66;">}</span></div></li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;"><div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">}</span></div></li></ol></div></div></div>
</div>
</div>
<div class="section" id="zend.gdata.youtube.other" name="zend.gdata.youtube.other"><div class="info"><h1 class="title">Other Functions</h1></div>
<p class="para">
In addition to the functionality described above, the YouTube <acronym class="acronym">API</acronym>
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 <acronym class="acronym">API</acronym> include:
ratings, comments, playlists, subscriptions, user profiles, contacts and messages.
</p>
<p class="para">
Please refer to the full documentation available in the <a href="http://code.google.com/apis/youtube/developers_guide_php.html" class="link external">» PHP Developer's
Guide</a> on code.google.com.
</p>
</div>
</div>
<hr />
<table width="100%">
<tr>
<td width="25%" style="text-align: left;">
<a href="zend.gdata.photos.html">Using Picasa Web Albums</a>
</td>
<td width="50%" style="text-align: center;">
<div class="up"><span class="up"><a href="zend.gdata.html">Zend_Gdata</a></span><br />
<span class="home"><a href="manual.html">Programmer's Reference Guide</a></span></div>
</td>
<td width="25%" style="text-align: right;">
<div class="next" style="text-align: right; float: right;"><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></div>
</td>
</tr>
</table>
</td>
<td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
float: left;
width: 186px;
padding: 5px;
font-size: smaller;
}
ul.toc {
margin: 0px 5px 5px 5px;
padding: 0px;
}
ul.toc li {
font-size: 85%;
margin: 1px 0 1px 1px;
padding: 1px 0 1px 11px;
list-style-type: none;
background-repeat: no-repeat;
background-position: center left;
}
ul.toc li.header {
font-size: 115%;
padding: 5px 0px 5px 11px;
border-bottom: 1px solid #cccccc;
margin-bottom: 5px;
}
ul.toc li.active {
font-weight: bold;
}
ul.toc li a {
text-decoration: none;
}
ul.toc li a:hover {
text-decoration: underline;
}
</style>
<ul class="toc">
<li class="header home"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="manual.html">Programmer's Reference Guide</a></li>
<li class="header up"><a href="reference.html">Zend Gdata Reference</a></li>
<li class="header up"><a href="zend.gdata.html">Zend_Gdata</a></li>
<li><a href="zend.gdata.analytics.html">Using Google Analytics</a></li>
<li><a href="zend.gdata.authsub.html">Authenticating with AuthSub</a></li>
<li><a href="zend.gdata.books.html">Using the Book Search Data API</a></li>
<li><a href="zend.gdata.clientlogin.html">Authenticating with ClientLogin</a></li>
<li><a href="zend.gdata.calendar.html">Using Google Calendar</a></li>
<li><a href="zend.gdata.docs.html">Using Google Documents List Data API</a></li>
<li><a href="zend.gdata.spreadsheets.html">Using Google Spreadsheets</a></li>
<li><a href="zend.gdata.gapps.html">Using Google Apps Provisioning</a></li>
<li><a href="zend.gdata.photos.html">Using Picasa Web Albums</a></li>
<li class="active"><a href="zend.gdata.youtube.html">Using the YouTube Data API</a></li>
<li><a href="zend.gdata.exception.html">Catching Gdata Exceptions</a></li>
</ul>
</td>
</tr>
</table>
</body>
</html>
|