Skip to content

Instantly share code, notes, and snippets.

@djalmaaraujo
Created April 30, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djalmaaraujo/2562761 to your computer and use it in GitHub Desktop.
Save djalmaaraujo/2562761 to your computer and use it in GitHub Desktop.
PHP Youtube uploader + zend
<?php
session_start();
$user_developer_key = 'KEY DO USUARIO';
$username = 'LOGIN CONTA GOOGLE';
$password = 'SENHA';
//init zend uploader
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
# Client
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $username,
$password = $password,
$service = 'youtube',
$client = null,
$source = 'TIM Namorados',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL
);
$yt = new Zend_Gdata_YouTube(
$httpClient,
'TIM Namorados',
null,
$user_developer_key);
if (($_GET['status'] != 200) && empty($_GET['id'])) {
$myVideoEntry= new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// Note that category must be a valid YouTube category
$myVideoEntry->setVideoCategory('Comedy');
$myVideoEntry->SetVideoTags('cars, funny');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
if ($postUrl) {
$nextUrl = 'http://localhost/zend/';
$form = '<form action="'. $postUrl .'?nexturl='. $nextUrl .
'" method="post" enctype="multipart/form-data">'.
'<input name="file" type="file"/>'.
'<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
'<input value="Upload Video File" type="submit" />'.
'</form>';
echo $form;
}
} else {
$videoId = $_GET['id'];
$videoEntry = $yt->getVideoEntry($videoId);
$control = $videoEntry->getControl();
if ($control instanceof Zend_Gdata_App_Extension_Control) {
if ($control->getDraft() != null &&
$control->getDraft()->getText() == 'yes') {
$state = $videoEntry->getVideoState();
if ($state instanceof Zend_Gdata_YouTube_Extension_State) {
print 'Upload status: '
. $state->getName()
.' '. $state->getText();
} else {
print 'Not able to retrieve the video status information'
.' yet. ' . "Please try again shortly.\n";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment