【问题标题】:Form Creation for Youtube API Direct UploadYoutube API 直接上传的表单创建
【发布时间】:2011-01-21 03:13:25
【问题描述】:

所以我有一个将视频上传到 youtube 的脚本:

$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
$myVideoEntry->setVideoCategory('Autos');
$myVideoEntry->setVideoPrivate();
$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://example.com/formprocess.php';

// build the form
$form = '<form id="youtube_upload" action="'. $postUrl .'?nexturl='. $nextUrl .
        '" method="post" enctype="multipart/form-data" target="uploader">'. 
        '<input id="video_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" />'. 
        '</form><iframe id="uploader" name="uploader" style="display: none; width: 500px; height: 200px; border:1px solid #000;"></iframe>
';

echo $form;

这是完美的工作。我遇到的唯一问题是我无法通过表单命名我的视频。我希望能够输入视频的标题、描述等,然后上传它们。想法?

【问题讨论】:

  • 为什么要使用表单直接上传?不就是浏览器上传吗?

标签: php youtube-api


【解决方案1】:

这是 Google/Youtube 数据 API 的基本部分:

$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle($ytTitle); // Set the title
$myVideoEntry->setVideoDescription($ytDesc); // Set the description
$myVideoEntry->setVideoCategory($ytCat);
$myVideoEntry->SetVideoTags($ytTags);

最好阅读所有 API 文档;因为里面有很多功能。

【讨论】:

    猜你喜欢
    • 2014-09-21
    • 2016-03-30
    • 1970-01-01
    • 2015-06-24
    • 2011-05-24
    • 2018-10-28
    • 2013-04-12
    • 2012-04-01
    • 1970-01-01
    相关资源
    最近更新 更多