本文整理汇总了PHP中Zend_Gdata_YouTube::getFormUploadToken方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Gdata_YouTube::getFormUploadToken方法的具体用法?PHP Zend_Gdata_YouTube::getFormUploadToken怎么用?PHP Zend_Gdata_YouTube::getFormUploadToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Gdata_YouTube
的用法示例。
在下文中一共展示了Zend_Gdata_YouTube::getFormUploadToken方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: browserBasedUpload
function browserBasedUpload($username, $password, $source, $title, $des = '', $cate = 'Entertainment')
{
// Note that this example creates an unversioned service object.
// You do not need to specify a version number to upload content
// since the upload behavior is the same for all API versions.
$httpClient = $this->clientLogin($username, $password, $source);
$yt = new Zend_Gdata_YouTube($httpClient);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($title);
$myVideoEntry->setVideoDescription($des);
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory($cate);
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try {
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
return $tokenArray;
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
}
示例2: actionFormData
/**
* Prints a JSON with URL for form action and the needed token, and dies.<br />
* Used with JSON POST requests.<br />
* <p>Asks for the following POST fields:
* <ul>
* <li>title</li>
* <li>description</li>
* <li>category (only one)</li>
* <li>keywords (comma-separated)</li>
* </ul>
* </p>
* @return JSON
*/
public function actionFormData()
{
Yii::import('system.collections.*');
Yii::import('system.base.*');
Yii::import('ext.*');
Yii::import('ext.Zend.Gdata.*');
require_once 'Zend/Loader.php';
Yii::registerAutoloader(array('Zend_Loader', 'loadClass'));
$login = Zend_Gdata_ClientLogin::getHttpClient($this->youtubeLogin, $this->youtubePassword, 'youtube', null, Yii::app()->name);
$login->setHeaders('X-GData-Key', 'key=' . $this->youtubeDevKey);
$utub = new Zend_Gdata_YouTube($login);
$video = new Zend_Gdata_YouTube_VideoEntry();
$media = $utub->newMediaGroup();
$media->title = $utub->newMediaTitle()->setText($_POST['title']);
$media->description = $utub->newMediaDescription()->setText($_POST['description']);
$media->keywords = $utub->newMediaKeywords()->setText($_POST['keywords']);
$media->category = array($utub->newMediaCategory()->setText($_POST['category'])->setScheme(self::CAT_SCHEME), $utub->newMediaCategory()->setText(preg_replace('/\\s/', '', Yii::app()->name) . 'Site')->setScheme(self::TAG_SCHEME));
$video->mediaGroup = $media;
$data = $utub->getFormUploadToken($video);
exit(json_encode($data));
}
示例3: createUploadForm
/**
* Create upload form by sending the incoming video meta-data to youtube and
* retrieving a new entry. Prints form HTML to page.
*
* @param string $VideoTitle The title for the video entry.
* @param string $VideoDescription The description for the video entry.
* @param string $VideoCategory The category for the video entry.
* @param string $VideoTags The set of tags for the video entry (whitespace separated).
* @param string $nextUrl (optional) The URL to redirect back to after form upload has completed.
* @return void
*/
function createUploadForm($videoTitle, $videoDescription, $videoCategory, $videoTags, $nextUrl = null)
{
$httpClient = getAuthSubHttpClient();
$youTubeService = new Zend_Gdata_YouTube($httpClient);
$newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$newVideoEntry->setVideoTitle($videoTitle);
$newVideoEntry->setVideoDescription($videoDescription);
//make sure first character in category is capitalized
$videoCategory = strtoupper(substr($videoCategory, 0, 1)) . substr($videoCategory, 1);
$newVideoEntry->setVideoCategory($videoCategory);
// convert videoTags from whitespace separated into comma separated
$videoTagsArray = explode(' ', trim($videoTags));
$newVideoEntry->setVideoTags(implode(', ', $videoTagsArray));
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try {
$tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, $tokenHandlerUrl);
if (loggingEnabled()) {
logMessage($httpClient->getLastRequest(), 'request');
logMessage($httpClient->getLastResponse()->getBody(), 'response');
}
} catch (Zend_Gdata_App_HttpException $httpException) {
print 'ERROR ' . $httpException->getMessage() . ' HTTP details<br /><textarea cols="100" rows="20">' . $httpException->getRawResponseBody() . '</textarea><br />' . '<a href="session_details.php">' . 'click here to view details of last request</a><br />';
return;
} catch (Zend_Gdata_App_Exception $e) {
print 'ERROR - Could not retrieve token for syndicated upload. ' . $e->getMessage() . '<br /><a href="session_details.php">' . 'click here to view details of last request</a><br />';
return;
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
if (!$nextUrl) {
$nextUrl = $_SESSION['homeUrl'];
}
print <<<END
<br /><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>
END;
}
示例4: getAuthSubHttpClient
$videoTags = null;
$nextUrl = null;
$httpClient = getAuthSubHttpClient();
$youTubeService = new Zend_Gdata_YouTube($httpClient);
$newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$newVideoEntry->setVideoTitle($videoTitle);
$newVideoEntry->setVideoDescription($videoDescription);
//make sure first character in category is capitalized
$videoCategory = strtoupper(substr($videoCategory, 0, 1)) . substr($videoCategory, 1);
$newVideoEntry->setVideoCategory($videoCategory);
// convert videoTags from whitespace separated into comma separated
$videoTagsArray = explode(' ', trim($videoTags));
$newVideoEntry->setVideoTags(implode(', ', $videoTagsArray));
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try {
$tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, $tokenHandlerUrl);
if (loggingEnabled()) {
logMessage($httpClient->getLastRequest(), 'request');
logMessage($httpClient->getLastResponse()->getBody(), 'response');
}
} catch (Zend_Gdata_App_HttpException $httpException) {
print 'ERROR ' . $httpException->getMessage() . ' HTTP details<br /><textarea cols="100" rows="20">' . $httpException->getRawResponseBody() . '</textarea><br />' . '<a href="session_details.php">' . 'click here to view details of last request</a><br />';
return;
} catch (Zend_Gdata_App_Exception $e) {
print 'ERROR - Could not retrieve token for syndicated upload. ' . $e->getMessage() . '<br /><a href="session_details.php">' . 'click here to view details of last request</a><br />';
return;
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
if (!$nextUrl) {
示例5: displayYouTubeUploadFilePage
/**
* displayYouTubeUploadFilePage
*
* Takes the post data from the previous form, sends to youtube, creates new entry,
* and prints the video file upload form.
*
* @return void
*/
function displayYouTubeUploadFilePage()
{
$this->displayHeader();
$videoTitle = '';
$videoDescription = '';
if (isset($_POST['title'])) {
$videoTitle = strip_tags($_POST['title']);
}
if (isset($_POST['description'])) {
$videoDescription = strip_tags($_POST['description']);
}
$videoCategory = isset($_POST['category']) ? $_POST['category'] : '';
$videoUnlisted = isset($_POST['unlisted']) ? true : false;
// Create fcms video - we update after the youtube video is created
$sql = "INSERT INTO `fcms_video` (\n `source_id`, \n `title`, \n `description`, \n `source`, \n `created`, \n `created_id`, \n `updated`, \n `updated_id`\n )\n VALUES\n ('0', ?, ?, 'youtube', NOW(), ?, NOW(), ?)";
$params = array($videoTitle, $videoDescription, $this->fcmsUser->id, $this->fcmsUser->id);
$lastId = $this->fcmsDatabase->insert($sql, $params);
if ($lastId === false) {
$this->fcmsError->displayError();
$this->displayFooter();
return;
}
// Save fcms video id
$_SESSION['fcmsVideoId'] = $lastId;
$sessionToken = $this->getSessionToken($this->fcmsUser->id);
$youtubeConfig = getYouTubeConfigData();
$httpClient = getYouTubeAuthSubHttpClient($youtubeConfig['youtube_key'], $sessionToken);
if ($httpClient === false) {
// Error message was already displayed by getYouTubeAuthSubHttpClient()
$this->displayFooter();
die;
}
$youTubeService = new Zend_Gdata_YouTube($httpClient);
$newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$newVideoEntry->setVideoTitle($videoTitle);
$newVideoEntry->setVideoDescription($videoDescription);
$newVideoEntry->setVideoCategory($videoCategory);
// make video unlisted
if ($videoUnlisted) {
$unlisted = new Zend_Gdata_App_Extension_Element('yt:accessControl', 'yt', 'http://gdata.youtube.com/schemas/2007', '');
$unlisted->setExtensionAttributes(array(array('namespaceUri' => '', 'name' => 'action', 'value' => 'list'), array('namespaceUri' => '', 'name' => 'permission', 'value' => 'denied')));
$newVideoEntry->setExtensionElements(array($unlisted));
}
try {
$tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, 'http://gdata.youtube.com/action/GetUploadToken');
} catch (Exception $e) {
echo '
<div class="error-alert">
<p>' . T('Could not retrieve token for syndicated upload.') . '</p>
<p>' . $e->getMessage() . '</p>
</div>';
$this->displayFooter();
return;
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
$nextUrl = getDomainAndDir() . 'video.php?upload=youtube';
echo '
<form action="' . $postUrl . '?nexturl=' . $nextUrl . '" method="post" enctype="multipart/form-data">
<fieldset>
<legend><span>' . T_('Upload YouTube Video') . '</span></legend>
<div class="field-row">
<div class="field-label"><label><b>' . T_('Title') . '</b></label></div>
<div class="field-widget"><b>' . $videoTitle . '</b></div>
</div>
<div class="field-row">
<div class="field-label"><label><b>' . T_('Video') . '</b></label></div>
<div class="field-widget">
<input type="file" name="file" size="50"/>
</div>
</div>
<input name="token" type="hidden" value="' . $tokenValue . '"/>
<input class="sub1" type="submit" id="upload_file" name="upload_file" value="' . T_('Upload') . '"/>
</fieldset>
</form>';
$this->displayFooter();
}