Difference between #2 and #3 of YouTube API v2.0 – Browser-based Uploading

YouTube API v2.0 – Browser-based Uploading
Video upload, yii, Youtube, API
Through the YouTube API you can upload files directly to the Youtube server.
Youtube currently offers two services 1. Direct Link 2. Browser Based Uploading.
In this wiki I will demonstrate how you can quickly set Browser Based Uploading
for your Yii application. This is the protocol request that takes place.

"Process Flow")

However, Before you read further please note that this functionality will not
work on a localhost. You need your application live so that Google can finish
the protocol request.

1. You would need to download the Zend Gdata framework the current stable
version is
1.12.0. http://framework.zend.com/download/gdata/

2. Extract the contents to /protected/vendors/ . You would need to create the
vendors folder. The folder structure should look like /protected/vendors/Zend .

3. Once that is you would need to create a youtube account and generate a
developer key. The youtube account can be created on youtube.com (if you don't
have a valid gmail account). I personally prefer a new account for my

4. In your main controller file create the following function. We do this in
order to call the video upload function explicitly.

	public function actionVideo()
5. In your protected/views/current-controller name folder create a video.php
file and copy the contents of the code below to the file.


require_once 'Zend/Loader.php';

     $authenticationURL = 'https://www.google.com/accounts/ClientLogin';

     $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
                      $username          = 'Your youtube id here without
                      $password           = 'Your password',
                      $service           = 'youtube',
                      $client           = null,
                      $source           = 'Your application name',
                      $loginToken           = null,
                      $loginCaptcha      = null,

     $devkey = 'Your very long developer key here';

          $yt = new Zend_Gdata_YouTube($httpClient, '', '', $devkey);
          $video = new Zend_Gdata_YouTube_VideoEntry();
          $video->setVideoTitle('Your video title);
          $video->setVideoDescription('Description of the video');
          $video->setVideoCategory('Select a category'); // see Youtube. Else
you may get an error. Avoid using People & Blogs. People alone or Blogs
alone is good.
          $handler_url     = 'http://gdata.youtube.com/action/GetUploadToken';
          $token_array     = $yt->getFormUploadToken($video, $handler_url);
          $token          = $token_array['token'];
          $post_url     = $token_array['url'];
          $next_url      =

<form action="<?php echo $post_url ?>?nexturl=<?php echo
$next_url ?>"
method="post" enctype="multipart/form-data">
     <input name="file" type="file"/>
     <input name="token" type="hidden"
value="<?php echo $token ?>"/>
     <input value="Upload Video File" type="submit" />

So how does it work. When you call the url

A request is sent to youtube for fileupload by sending certain parameters like
Video Title, Category etc.. Youtube returns request with your token (temporary).
The user is displayed the upload video field. Once the User submits the video.
Youtube returns the video ID and status message to the url you set in the
$next_url. For example.


This ID would be your youtube video ID which you can store in your database.

You can also watch this in action here at