API of the week: YouTube!!!
Yep, you got that right, the API of this week and if not of the month is YouTube. YouTube just released a new set of API that will allow you or users to upload video directly to youtube from anywhere. And that is not it, it even allows video feedback uploads. So yeah, from there you can build a sweet social community based on it.
So anyway, I was thinking of what to develop with this new API…Google Maps? Naah.. something more useful, and so of course..the best ideal situation to use the API is with a web form! So I built something really quick with MooTools (Ajax framework) where a user can submit either videos (going to YouTube) or Pictures (Going to flickr using API)…
So this is what I ended up with:

You can check it out at http://www.mrayyan.com/mooform/
But anyway, at the backend I’ve got Connection to YouTube going to upload the video once it is saved at the tmp folder… So instead of usingĀ "move_uploaded_file" php function, I just used my own function which I created:
newMediaFileSource($file);
$filesource->setContentType('video/mp4');
// set slug header
$filesource->setSlug($file);
// add the filesource to the video entry
$myVideoEntry->setMediaSource($filesource);
// create a new Zend_Gdata_YouTube_MediaGroup object
$mediaGroup = $yt->newMediaGroup();
$mediaGroup->title = $yt->newMediaTitle()->setText('My Test Movie');
$mediaGroup->description = $yt->newMediaDescription()->setText('My description');
// the category must be a valid YouTube category
// optionally set some developer tags (see Searching by Developer Tags for more details)
$mediaGroup->category = array(
$yt->newMediaCategory()->setText('Autos')->setScheme('http://gdata.youtube.com/schemas/2007/categories.cat'),
$yt->newMediaCategory()->setText('mydevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat'),
$yt->newMediaCategory()->setText('anotherdevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat')
);
// set keywords
$mediaGroup->keywords = $service->newMediaKeywords()->setText('cars, funny');
$myVideoEntry->mediaGroup = $mediaGroup;
// set video location
$yt->registerPackage('Zend_Gdata_Geo');
$yt->registerPackage('Zend_Gdata_Geo_Extension');
$where = $yt->newGeoRssWhere();
$position = $yt->newGmlPos('37.0 -122.0');
$where->point = $yt->newGmlPoint($position);
$entry->setWhere($where);
// upload URL for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
try {
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
}
?>
and the Auth file you need "to authenticate with youtube… it is called by the function" is:
setHeaders('X-GData-Key', "key=${myDeveloperKey}");
?>
And that is it.. great huh?
Powered by Qumana
Sphere: Related ContentIf you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments
No comments yet.
Leave a comment