Created
June 24, 2011 06:58
-
-
Save junichi11/1044349 to your computer and use it in GitHub Desktop.
CakePHP Zend GData Youtube unlisted upload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome. Thanks so much!