Saturday, December 11, 2010

Updates to my bread and butter.

I just updated my YouTube library to incorporate a suggestion to allow direct uploading from your server to the YouTube servers. The new method is called "directUpload" and takes 4 parameters. The first is the path to the file to upload from your server. The second is the mime-type of the video (video/mp4, etc.). The third is the XML meta data that goes with this video, you can learn what this is here but it is essentially the same as what you would do for a form upload token. The final parameter is optional and defines the user whose account this belongs to, if you leave it blank it will go to the currently authenticated user.

Here is a sample call with the video to upload in the CI root directory:

$xml = '<?xml version="1.0"?><entry xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" xmlns:yt="http://gdata.youtube.com/schemas/2007"><media:group><media:title type="plain">Test Video</media:title><media:description type="plain">This is a direct upload test</media:description><media:category scheme="http://gdata.youtube.com/schemas/2007/categories.cat">People</media:category><media:keywords>test, upload</media:keywords></media:group></entry>';

$this->youtube->directUpload("test.3gp", 'video/3gp', $xml);

You may wish to note that uploading a large file could take awhile and this library doesn't currently support resumable uploads so you just have to wait it out if things are taking awhile. As always you can turn on the DEBUG flag at the top and watch your error log for more info on what is going on.

While I was in there I took the liberty to fix a bug where only a response of 200 was deemed success by the library now any 200 level response is considered successful as it should be.

Here is the updated library: http://dl.dropbox.com/u/13081549/youtube.php

If you are new here consult my other posts for more information.

4 comments:

  1. I got my consumer key and secret and my youtube developer key,How does one get the access key ie
    $params['oauth']['access_token'] ??

    ReplyDelete
  2. Works like a charm. It never seems to return the response from youtube though, even though it uploads correctly. Is that the way it's supposed to work? Or am I missing something....

    ReplyDelete
  3. According to the Developers Guide: "When you submit an Upload API request, the API returns an Atom entry that contains information about the uploaded video. The entry has the same format as an entry that would appear in a user's uploaded videos feed."

    So something is not working correctly. I will investigate it further.

    ReplyDelete
  4. For some reason direct upload does not return a chunk size which the read method requires. I fixed the read method so that it will attempt to handle situations with no chunk size. That seems to have resolved the issue.

    ReplyDelete