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 83 84 85 86 87 88 89 90
| public function youtube_auth(){
/* ********************************************************************************
* Les inclusions de script
* ********************************************************************************/
set_include_path(get_include_path().PATH_SEPARATOR.FCPATH.'/application/libraries');
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
require_once 'Zend/Gdata/YouTube.php';
require_once 'Zend/Gdata/ClientLogin.php';
/* ********************************************************************************
* ETAPE 1 => Authentification
* ********************************************************************************/
// configuration et identifiants
$authenticationURL = 'https://www.google.com/youtube/accounts/ClientLogin'; // Url pour s'identifier
$developerKey = 'VALID-KEY-HERE'; // Clé développeur
$applicationId = 'ytapi-SocialPlatform'; // Identifiant de l'application
$clientId = NULL; // Identifiant Client
$username = "valid-email@example.com"; // Login/adresse mail de votre compte YouTube
$password = "my-password"; // Mot de passe de votre compte YouTube
// authentification via la méthode HTTP
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username,$password,'youtube',null,'MonSiteWeb',null,null,$authenticationURL
);
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
/* ********************************************************************************
* ETAPE 2 => Envoie des d'Informations sur la vidéo
* ********************************************************************************/
// création d'un nouvel objet video
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// on donne des informations sur notre vidéo
$myVideoEntry->setVideoTitle('Test1');
$myVideoEntry->setVideoDescription('Bah c est un test quoi !');
$myVideoEntry->setVideoCategory('Sports'); // La catégorie doit correspondre à une catégorie YouTube
$myVideoEntry->SetVideoTags('test, essai');
$myVideoEntry->SetVideoDeveloperTags(array('mydevtag','anotherdevtag'));
/* ********************************************************************************
* ETAPE 3 => Récupération du Token unique
* ********************************************************************************/
// Récupération du token
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try{
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
}
catch ( Zend_Gdata_HttpException $e ){
print "Error ZendGdataException";
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
/* ********************************************************************************
* ETAPE 4 => Envoie de la vidéo
* ********************************************************************************/
// Page sur laquelle sera renvoyé l'utilisateur après la validation
// du formulaire (URL de retour)
$nextUrl = 'http://s390075769.onlinehome.fr/index.php?/site/';
// Affichage du formulaire
$form = '<form action="'. 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="'. $tokenValue .'"/>
<input value="Envoyer la vidéo" type="submit" />
</form>';
echo $form;
} |
Partager