Techno

PHP youtube upload @ technoslab.blogspot.com

Apr 13th, 2011
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.49 KB | None | 0 0
  1. <?php
  2.  
  3. /* POSTED AT TECHNOSLAB.BLOGSPOT.COM */
  4.  
  5. /* DOWNLOAD REQUIRED LIBRARIES : http://framework.zend.com/download/gdata */
  6.  
  7. require_once 'Zend/Loader.php';
  8.  
  9. Zend_Loader::loadClass('Zend_Gdata_YouTube');
  10.  
  11. Zend_Loader::loadClass('Zend_Gdata_AuthSub');
  12.  
  13. Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  14.  
  15. $yt = new Zend_Gdata_YouTube();
  16.  
  17. $authenticationURL= 'https://www.google.com/accounts/ClientLogin';
  18.  
  19. /* AUTH :: ENTER YOUR USERNAME / PASSWORD */
  20.  
  21. $user = "YOUTUBE_COM_USER";
  22.  
  23. $pass = "YOUTUBE_COM_PASS";
  24.  
  25. /* API :: GET THEM FROM http://code.google.com/apis/youtube/dashboard/gwt/index.html */
  26.  
  27. $apiKEY = "YOUR_API_KEY";
  28.  
  29. $apiNAME = "YOUR_API_NAME";
  30.  
  31. $video_path = "sample.mov"; // WITH PROPER PATH
  32.  
  33. $video_type = "video/quicktime"; // VIDEO TYPE : http://www.w3schools.com/media/media_mimeref.asp
  34.  
  35. $video_title = "Sample video upload"; // TITLE FOR VIDEO
  36.  
  37. $video_description = "Blah blah blah... Checking upload.."; // DESCRIPTION
  38.  
  39. $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
  40.               $username = $user,
  41.               $password = $pass,
  42.               $service = 'youtube',
  43.               $client = null,
  44.               $source = $apiNAME,
  45.               $loginToken = null,
  46.               $loginCaptcha = null,
  47.               $authenticationURL
  48.             );
  49.              
  50. $yt = new Zend_Gdata_YouTube($httpClient,'','',$apiKEY);
  51.  
  52. $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  53.  
  54. $filesource = $yt->newMediaFileSource($video_path);
  55.  
  56. $filesource->setContentType($video_type);
  57.  
  58. $filesource->setSlug('file.mov');
  59.  
  60. $myVideoEntry->setMediaSource($filesource);
  61.  
  62. $myVideoEntry->setVideoTitle($video_title);
  63.  
  64. $myVideoEntry->setVideoDescription($video_description);
  65.  
  66. $myVideoEntry->setVideoCategory('Autos');
  67.  
  68. $myVideoEntry->SetVideoTags('cars, funny');
  69.  
  70. $myVideoEntry->setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));
  71.  
  72. $yt->registerPackage('Zend_Gdata_Geo');
  73.  
  74. $yt->registerPackage('Zend_Gdata_Geo_Extension');
  75.  
  76. $where = $yt->newGeoRssWhere();
  77.  
  78. $position = $yt->newGmlPos('37.0 -122.0');
  79.  
  80. $where->point = $yt->newGmlPoint($position);
  81.  
  82. $myVideoEntry->setWhere($where);
  83.  
  84. $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
  85.  
  86. try{
  87.  
  88.     $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
  89.  
  90. }catch(Zend_Gdata_App_HttpException $httpException){
  91.  
  92.     echo $httpException->getRawResponseBody();
  93.  
  94. }catch (Zend_Gdata_App_Exception $e){
  95.  
  96.     echo $e->getMessage();
  97.  
  98. }
  99.  
  100. echo "UPLOAD SUCCESSFULLY";
  101.  
  102. ?>
Advertisement
Add Comment
Please, Sign In to add comment