Skip to content

Instantly share code, notes, and snippets.

@junichi11
Created June 24, 2011 06:58
Show Gist options
  • Save junichi11/1044349 to your computer and use it in GitHub Desktop.
Save junichi11/1044349 to your computer and use it in GitHub Desktop.
CakePHP Zend GData Youtube unlisted upload
<?php
class YoutubeController extends AppController{
public $name = 'Youtube';
public $uses = array();
public $layout = 'default';
public $components = array('Zend','Auth');
public function upload(){
$this->Zend->loadClass('Zend_Gdata_ClientLogin');
$this->Zend->loadClass('Zend_Gdata_YouTube');
//
$client = Zend_Gdata_ClientLogin::getHttpClient(ZEND_GDATA_CLIENT_EMAIL, ZEND_GDATA_CLIENT_PASS, 'youtube');
$client->setHeaders('X-GData-Key', "key=".ZEND_GDATA_YOUTUBE_DEVELOPER_KEY);
$yt = new Zend_Gdata_YouTube($client);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// unlisted upload
$accessControlElement = new Zend_Gdata_App_Extension_Element(
'yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', ''
);
$accessControlElement->extensionAttributes = array(
array(
'namespaceUri' => '',
'name' => 'action',
'value' => 'list'
),
array(
'namespaceUri' => '',
'name' => 'permission',
'value' => 'denied'
));
$myVideoEntry->extensionElements = array($accessControlElement);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Sports');
// $myVideoEntry->setVideoPrivate();
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
$nextUrl = "http://yourhostname/youtube/upload";
$this->set('tokenValue', $tokenValue);
$this->set('postUrl', $postUrl);
$this->set('nextUrl', $nextUrl);
}
}
?>
@foxinni
Copy link

foxinni commented Jan 18, 2013

Awesome. Thanks so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment