我从我的网站获得了将视频上载到YouTubeAccount的代码:
<?php
session_start();
set_time_limit(0);
ini_set('memory_limit', '150M');
ini_set('upload_max_filesize', '30M');
ini_set('default_socket_timeout', '6000');
ini_set('max_input_time', '6000');
ini_set('post_max_size', '100M');
ini_set('max_execution_time', '6000');
$clientLibraryPath = 'library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
//include Zend Gdata Libs
require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/MediaFileSource.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');
//yt account info
$yt_user = 'xx'; //youtube username or gmail account
$yt_pw = 'xx'; //account password
$yt_source = 'xx'; //name of application (can be anything)
//yt dev key
$yt_api_key = 'xx'; //your youtube developer key
//login in to YT
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pw,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle('The Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Autos');
$myVideoEntry->SetVideoTags('cars, funny');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
$nextUrl = 'http://sabinequardon.dk';
// build the form
$form = '<form id="youtube_upload" action="'. $postUrl .'?nexturl='. $nextUrl .
'" method="post" enctype="multipart/form-data" target="uploader">'.
'<input id="title" name="video_title" type="text"/>'.
'<input id="file_upload" name="file_upload" type="file"/>'.
'<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
'<input value="Upload Video File" type="submit" id="submit" />'.
'</form>
';
echo $form;
?>
我并不擅长php,这是我第一次尝试使用youtube api。一直在尽我所能地阅读,但似乎没有多大帮助。
我知道在上传视频之前我先得到元数据?
我需要用户自己写标题,所以所有视频的名称都不一样。
有办法吗?
我试着到处找,但似乎找不到正确的答案。
如果用户上传的所有视频都被称为同一视频,那就太烦人了。
谢谢您。
最佳答案
此行设置视频标题:
$myVideoEntry->setVideoTitle('The Movie');
由于您已经在表单中输入了标题,因此可以简单地使用它:
$video_title = $_POST['video_title'];
$myVideoEntry->setVideoTitle($video_title);
或者简单地说:
$myVideoEntry->setVideoTitle($_POST['video_title']);
关于php - Zend框架,YouTube API,默认标题(基于浏览器的上传),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9350478/