1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
| <?php
/* ********************************************************************************
* Les inclusions de script
* ********************************************************************************/
require_once 'Zend/Gdata/YouTube.php';
require_once 'Zend/Gdata/ClientLogin.php';
/* ********************************************************************************
* ETAPE 1 => Authentification
* ********************************************************************************/
$urlAuthentification = 'https://www.google.com/youtube/accounts/ClientLogin'; // Url pour s'identifier
$cleDeveloppement = 'ma clé de developpement'; // Notre clé de développeur
$idApplication = 'identificateur de l'appli'; // L'identificateur de l'application
$idClient = null; // L'identificateur du client => Déprécié
$email = 'adresse mail du compte'; // Le nom d'utilisateur du compte
$password = 'mon mot de passe'; // Le mot de passe du compte
// Identification via la méthode getHttpClient
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$email, $password, 'youtube', null, 'MonSiteWeb', null, null, $urlAuthentification
);
$youtube = new Zend_Gdata_YouTube( $httpClient, $idApplication, $idClient ,$cleDeveloppement );
/* ********************************************************************************
* ETAPE 2 => Envoie des d'Informations sur la vidéo
* ********************************************************************************/
$video = new Zend_Gdata_YouTube_VideoEntry() ;
/* Infos sur la vidéo */
$video->setVideoTitle( 'Titre de ma video' );
$video->setVideoDescription( 'Description de ma video' );
$video->setVideoCategory( 'Sports' );
$video->SetVideoTags( 'motclé1, motclé2' );
$video->SetVideoDeveloperTags(array( 'mydevtag', 'anotherdevtag' ) );
/* ********************************************************************************
* ETAPE 3 => Récupération du Token unique
* ********************************************************************************/
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try{
$tokenArray = $youtube->getFormUploadToken($video, $tokenHandlerUrl);
}
catch( Zend_Gdata_HttpException $e ){
print "Error ZendGdataException";
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
/* ********************************************************************************
* ETAPE 4 => Envoie de la vidéo
* ********************************************************************************/
// Fait en html
$nextUrl = 'http://localhost/Upload_Youtube/';
/* ********************************************************************************
* ETAPE 5 => Traitement des erreurs
* ********************************************************************************/
?>
<!-- Formulaire d'envoie de la vidéo -->
<form
action="<?php print htmlspecialchars( $postUrl, ENT_QUOTES ).'?nexturl='. urlencode( $nextUrl ) ?>"
method="post"
enctype="multipart/formdata"
>
Fichier vidéo : <input name="file" type="file" />
<input name="token" type="hidden" value="<?php print $tokenValue ?>"/>
<input type="submit" value="Envoyer la vidéo"/>
</form> |