【问题标题】:Zend framework, YouTube API, default title (Browserbased upload)Zend 框架、YouTube API、默认标题(基于浏览器的上传)
【发布时间】:2012-02-19 15:28:39
【问题描述】:

我得到了这个代码,用于从我的网站上传视频到我的 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。一直在阅读我能阅读的所有内容,但似乎没有多大帮助。 我知道在上传视频之前我先获取元数据?

我需要用户写他们自己的标题,所以所有视频的名字都不一样。

有没有办法做到这一点? 我试过到处找,似乎找不到正确的答案。 如果用户上传的所有视频都被称为相同的名称,那就很烦人了。

谢谢。

【问题讨论】:

  • 你从哪里得到的代码?它按原样工作吗?
  • 我自己通过浏览互联网将其混合在一起。有用。视频已上传,但名称相同。

标签: php zend-framework metadata youtube-api title


【解决方案1】:

这一行设置视频标题:

$myVideoEntry->setVideoTitle('The Movie');

由于您已经在表单中输入了标题,您可以简单地使用它:

$video_title = $_POST['video_title'];
$myVideoEntry->setVideoTitle($video_title);

或者简单地说:

$myVideoEntry->setVideoTitle($_POST['video_title']);

【讨论】:

  • 如果我们将文件直接发送到 youtube(通过 zend 客户端登录)会有什么帮助?如果我们不通过我们的主机发送呢?
猜你喜欢
  • 1970-01-01
  • 2013-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-06
  • 1970-01-01
  • 1970-01-01
  • 2017-05-06
相关资源
最近更新 更多