1
我要上传与未来路视频:Yii + Zend gdata。的Youtube上传
- 我只是上传文件到服务器(像往常一样)
- 我的服务器端Yii开发的应用程序需要从一个特殊的YouTube上的视频,并上传帐户在YouTube上
我有什么:
- 我的YouTube(谷歌)帐户名和电子邮件。 “名”或“[email protected]”
- 我的密码
- 开发人员密钥,这是我在谷歌的“产品仪表板”
- 的应用程序,它的名字“MYAPP”的名称发现:
Product Dashboard: myapp
所以,我读了一些谷歌文档和决定,对我来说最好的办法是使用ClientLogin认证类型,因为我只有一个账号使用,我拥有所有必要的数据。我找到了一个ZendFramework的GData的例子,并将其导入到我的Yii应用程序中。
我特意简化了代码,只是为了从/ upload目录上传一个视频来测试它的工作。我希望能够上传我的YT帐户中的视频。当然,没有视频,在这里我:-)行动的完整代码如下:
Yii::import('application.vendors.*');
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$yt_user = 'myYTname';
$yt_pass = 'myYTpass';
$yt_source = 'myapp';
$yt_api_key = 'veryVERYlongKEYhere';
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pass,
$service = 'youtube',
$client = null,
$source = $yt_source,
$loginToken = null,
$loginCaptcha = null,
$authenticationURL
);
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, null, $yt_api_key);
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource(Yii::getpathOfAlias('webroot').'/upload/videos/video.mp4');
$filesource->setContentType('video/mp4');
$filesource->setSlug('video.mp4');
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie description');
$myVideoEntry->setVideoCategory('Autos');
$myVideoEntry->SetVideoTags('cars, funny');
$myVideoEntry->setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));
$uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/{$yt_user}/uploads";
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();
}
正如你所看到的,有来自官方的例子有很多默认的代码。但它不起作用。没有人回声显示我的信息。但是,当我删除的try-catch,我得到了一个错误:
Zend_Gdata_App_HttpException
Read timed out after 10 seconds
UPD 1:我通过在ZendHTTP类中设置新的超时参数来移除超时异常。所以现在我的应用程序的页面只是加载加载,然后显示nithong。 – Apfel
UPD 2:我试图上传的视频是300 Kb的大小,所以一定不需要传输数据,甚至10秒 – Apfel
UPD 3:我用XDebug调试了我的应用程序,发现有仍然愚蠢的超时豁免。 100秒超时上传一个300Kb的文件...有什么问题,但我不明白什么... – Apfel