Ver Mensaje Individual
  #1 (permalink)  
Antiguo 22/12/2012, 18:20
Avatar de dmm84
dmm84
 
Fecha de Ingreso: marzo-2011
Mensajes: 164
Antigüedad: 13 años, 10 meses
Puntos: 13
Subida de videos a YouTube con su API

Hola,
llevo bastante tiempo intentando realizar estas subidas pero hasta ahora no lo he conseguido. He usado el codigo de un tema que ya crearon en su momento (http://www.forosdelweb.com/f18/subir...mi-web-929998/) para ir probando a ver si funciona. No sabia si continuar ese tema o crear uno nuevo, aunque al final lo he creado.

Mi codigo es el siguiente, con el error solucionado que tenia el usuario de ese tema:

Código PHP:
Ver original
  1. require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
  2. Zend_Loader::loadClass('Zend_Gdata_YouTube');
  3. $yt = new Zend_Gdata_YouTube();
  4.  
  5. Zend_Loader::loadClass('Zend_Gdata_AuthSub');
  6. Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
  7.  
  8. // autenticacion
  9. $authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
  10. $httpClient = Zend_Gdata_ClientLogin::getHttpClient(
  11. $username = '[email protected]',
  12. $password = 'micontraseña',
  13. $service = 'youtube',
  14. $client = null,
  15. $source = 'miaplicacion', // a short string identifying your application
  16. $loginToken = null,
  17. $loginCaptcha = null,
  18. $authenticationURL);
  19.  
  20. $myDeveloperKey = 'LaClaveDeDeveloper'; // Esta clave la he obtenido de: http://code.google.com/apis/youtube/dashboard
  21.  
  22. $httpClient->setHeaders('X-GData-Key', "key=${myDeveloperKey}");
  23. $yt = new Zend_Gdata_YouTube($httpClient);
  24.  
  25. // subir video
  26. $yt = new Zend_Gdata_YouTube($httpClient);
  27. // create a new Zend_Gdata_YouTube_VideoEntry object
  28. $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
  29.  
  30. // create a new Zend_Gdata_App_MediaFileSource object
  31. $filesource = $yt->newMediaFileSource('file.mov');
  32. $filesource->setContentType('video/quicktime');
  33. // set slug header
  34. $filesource->setSlug('file.mov');
  35.  
  36. // add the filesource to the video entry
  37. $myVideoEntry->setMediaSource($filesource);
  38.  
  39. // create a new Zend_Gdata_YouTube_MediaGroup object
  40. $mediaGroup = $yt->newMediaGroup();
  41. $mediaGroup->title = $yt->newMediaTitle()->setText('My Test Movie');
  42. $mediaGroup->description = $yt->newMediaDescription()->setText('My description');
  43.  
  44. // the category must be a valid YouTube category
  45. // optionally set some developer tags (see Searching by Developer Tags for more details)
  46. $mediaGroup->category = array(
  47.     $yt->newMediaCategory()->setText('Autos')->setScheme('http://gdata.youtube.com/schemas/2007/categories.cat'),
  48.     $yt->newMediaCategory()->setText('mydevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat'),
  49.     $yt->newMediaCategory()->setText('anotherdevelopertag')->setScheme('http://gdata.youtube.com/schemas/2007/developertags.cat')
  50. );
  51.  
  52. // set keywords
  53. $myVideoEntry->SetVideoTags('cars, funny');
  54.  
  55. // set video location
  56. $yt->registerPackage('Zend_Gdata_Geo');
  57. $yt->registerPackage('Zend_Gdata_Geo_Extension');
  58. $where = $yt->newGeoRssWhere();
  59. $position = $yt->newGmlPos('37.0 -122.0');
  60. $where->point = $yt->newGmlPoint($position);
  61. $entry->setWhere($where);
  62.  
  63. //upload URL for the currently authenticated user
  64. $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
  65.  
  66. try {
  67.     $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
  68. } catch (Zend_Gdata_App_Exception $e) {
  69.     echo $e->getMessage();
  70. }

Y cuando intento usarlo me da el siguiente error:

Fatal error: Uncaught exception 'Zend_Gdata_App_AuthException' with message 'Authentication with Google failed. Reason: BadAuthentication' in /home/miapp/public_html/Zend/Gdata/ClientLogin.php:175 Stack trace: #0 /home/miapp/public_html/pruebas.php(19): Zend_Gdata_ClientLogin::getHttpClient('miusuario@g ma...', 'micontraseña', 'youtube', NULL, 'miaplicacion', NULL, NULL, 'https://www.goo...') #1 {main} thrown in /home/miapp/public_html/Zend/Gdata/ClientLogin.php on line 175

He probado mil formas y aun no se donde me equivoco. A ver si alguien me ilumina.
__________________
Mas vale un codigo que mil palabras