【问题标题】:How to upload video to Youtube using zend gdata如何使用 zend gdata 将视频上传到 Youtube
【发布时间】:2011-12-08 07:45:19
【问题描述】:

我已经登录了用户。我检索了他最喜欢的视频。但是当我尝试上传视频时出现错误

Fatal error File to be uploaded at does not exist or is not readable.

这是我用来上传视频的代码

         $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
         $file = '/files/trainingvideo1.mp4';
         $file = realpath($file);  
         $filesource = $yt->newMediaFileSource($file); 
         $filesource->setContentType('video/mp4'); 
         $filesource->setSlug($file);  
         $myVideoEntry->setMediaSource($filesource);  
         $myVideoEntry->setVideoTitle('Tutorial 1'); 
         $myVideoEntry->setVideoDescription('Tutorial 1'); 
         $myVideoEntry->setVideoCategory('Entertainment');  
         $myVideoEntry->SetVideoTags('testme');  
         $myVideoEntry->setVideoDeveloperTags(array('tester', 'test'));
         $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
         $newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');

感谢您的帮助。

【问题讨论】:

  • 你的真实路径返回不是假的吗?
  • @swiecki 返回错误。为什么是这样。我该如何解决这个问题
  • 好的,我会尽快更新我的答案

标签: php zend-framework cakephp youtube-api gdata


【解决方案1】:

编辑:根据您的 realpath() 返回 false 的信息,我们可以假设您可能正确配置了 zend gdata 并且只是传入了一个错误的文件。

这是关于 realpath() 的 PHP 文档:http://php.net/manual/en/function.realpath.php

重要的部分是:

realpath() returns FALSE on failure, e.g. if the file does not exist.

Note:

The running script must have executable permissions on all directories in the hierarchy, otherwise realpath() will return FALSE.

所以在这一点上,我会继续:

  1. 检查文件是否存在以及您的 URL 是否正确 - 可能首先尝试使用绝对 URL 来测试并逐步建立相对 URL
  2. 检查文件的权限,确保它可以被所有人执行(我认为是 755 unix 权限)

祝你好运!

Zend Gdata Youtube 文档:

可以通过以下两种方式之一上传视频:直接上传视频或仅发送视频元数据并让用户通过 HTML 表单上传视频。

为了直接上传视频,您必须首先构造一个新的 » Zend_Gdata_YouTube_VideoEntry 对象并指定一些必需的元数据。

下面的代码创建一个空白 » Zend_Gdata_YouTube_VideoEntry 来上传。然后使用一个 » Zend_Gdata_App_MediaFileSource 对象来保存实际的视频文件。在后台,» Zend_Gdata_YouTube_Extension_MediaGroup 对象用于保存所有视频的元数据。 $uploadUrl 是新条目发布到的位置。这可以使用当前经过身份验证的用户的 $userName 来指定,或者,您可以简单地使用字符串 'default' 来引用当前经过身份验证的用户。

$yt = new Zend_Gdata_YouTube($httpClient);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$filesource = $yt->newMediaFileSource('mytestmovie.mov');
$filesource->setContentType('video/quicktime');
$filesource->setSlug('mytestmovie.mov');

$myVideoEntry->setMediaSource($filesource);

$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// Note that category must be a valid YouTube category !
$myVideoEntry->setVideoCategory('Comedy');

// Set keywords, note that this must be a comma separated string
// and that each keyword cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');

// Optionally set some developer tags
$myVideoEntry->setVideoDeveloperTags(array('mydevelopertag',
                                           'anotherdevelopertag'));

// Optionally set the video's location
$yt->registerPackage('Zend_Gdata_Geo');
$yt->registerPackage('Zend_Gdata_Geo_Extension');
$where = $yt->newGeoRssWhere();
$position = $yt->newGmlPos('37.0 -122.0');
$where->point = $yt->newGmlPoint($position);
$myVideoEntry->setWhere($where);

// Upload URI for the currently authenticated user
$uploadUrl =
    'http://uploads.gdata.youtube.com/feeds/users/default/uploads';

// Try to upload the video, catching a Zend_Gdata_App_HttpException
// if available or just a regular Zend_Gdata_App_Exception

try {
    $newEntry = $yt->insertEntry($myVideoEntry,
                                 $uploadUrl,
                                 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
    echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
    echo $e->getMessage();
}

要将视频上传为私人视频,只需使用:$myVideoEntry->setVideoPrivate();在执行上传之前。 $videoEntry->isVideoPrivate() 可用于检查视频条目是否为私有。

来源:http://framework.zend.com/manual/en/zend.gdata.youtube.html

【讨论】:

  • 您的共享 zend 框架链接显示 404 页面未找到。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-31
  • 2012-06-07
  • 2012-04-03
  • 1970-01-01
相关资源
最近更新 更多