douyang5943 2012-03-23 18:43
浏览 83
已采纳

使用Zend Gdata上传YouTube视频的请求无效

I have the following code that returns HTTP error 400 everytime I try to execute it.

    $file = "/home/.../videos/bigbuckbunny.mp4";
    $title = "This is a test";
    $category = "Film";
    $description = "test";
    $keywords = "test, film, big buck";

    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    Zend_Loader::loadClass('Zend_Gdata_YouTube');  
    Zend_Loader::loadClass('Zend_Gdata_App_HttpException');  

    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($this->settings['username'], $this->settings['password'], 'youtube', NULL, 'Test Client');

    $this->youTube = new Zend_Gdata_YouTube($httpClient, 'Test Client', 'Videos Plugin', $this->settings['key']);
    $this->youTube->setMajorProtocolVersion(2);

    $entry = new Zend_Gdata_YouTube_VideoEntry();  

    $fileSource = $this->youTube->newMediaFileSource($file);  
    $fileSource->setContentType(mime_content_type($file));
    $fileSource->setSlug(basename($file));  

    $entry->setMediaSource($fileSource);  

    $entry->setVideoCategory($category);
    $entry->setVideoTitle($title);  
    $entry->setVideoDescription($description);  
    $entry->setVideoTags($keywords);  

    try
    {
        $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/default/uploads';
        $newEntry = $this->youTube->insertEntry($entry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');  
    }
    catch(Zend_Gdata_App_HttpException $e)
    {  
        var_dump($e->getResponse());
        return NULL;
    }

My settings are correct. The exception is the following:

object(Zend_Http_Response)#362 (5) {
  ["version:protected"]=>
  string(3) "1.1"
  ["code:protected"]=>
  int(400)
  ["message:protected"]=>
  string(11) "Bad Request"
  ["headers:protected"]=>
  array(9) {
    ["Server"]=>
    string(61) "HTTP Upload Server Built on Mar 22 2012 14:54:02 (1332453242)"
    ["Content-type"]=>
    string(24) "text/html; charset=UTF-8"
    ["X-guploader-uploadid"]=>
    string(98) "AEnB2UoljS9KYUftPEhuRV8hVssGvOHcR1mcK0rfhMOGTBkUYSxX29iKpO9vHisG10EYxQE0-rul3rVEbd2YJlFiXCbaGBpUpQ"
    ["Date"]=>
    string(29) "Fri, 23 Mar 2012 18:36:46 GMT"
    ["Pragma"]=>
    string(8) "no-cache"
    ["Expires"]=>
    string(29) "Fri, 01 Jan 1990 00:00:00 GMT"
    ["Cache-control"]=>
    string(35) "no-cache, no-store, must-revalidate"
    ["Content-length"]=>
    string(2) "15"
    ["Connection"]=>
    string(5) "close"
  }
  ["body:protected"]=>
  string(15) "Invalid Request"
}

Does anyone have any idea? I got it working before, now it doesn't seem to work.

  • 写回答

1条回答 默认 最新

  • dte29947 2012-03-23 18:58
    关注

    Turns out I had the wrong upload URL, it should have been:

    $uploadUrl = 'http://uploads.gdata.youtube.com/feeds/users/' . $this->settings['feed'] . '/uploads';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀