Uncaught exception ‘Zend_Gdata_App_HttpException’ with message ‘Expected response code 200, got 400

今天我在使用 gdata(來自 PHP Zend framework) 嘗試存取一段youtube video的影片的時候遇到了標題的error. 我使用了半個小時設定一個正確的 InstalltionChecker.php, 先排除我的伺服器已經裝有 php-xml libraries, ssl libraries, 但仍然無解. Google 沒有提供一個合用的答案.

最後我發現, 是youtube 判定該 video 違反了某些版權協定, 所以返回了 400錯誤碼, 正解是:

<?php
try {
  $yt = new Zend_Gdata_YouTube();
  $videoEntry = $yt->getVideoEntry($key);
} catch(Zend_Gdata_App_HttpException e) {
  //handle error
}
?>

Today i encountered the above error when i am trying to fetch youtube data given the video id using PHP Zend framework suggested by google. I had made half an hour top setup the InstallationChecker.php, which shows the installation had no errors. I further debug using xdebug, cross check php-xml libraries, ssl libraries on the server, but no clue. Google do not provide a solution.

In the end, youtube banned the video because of copyrights, but just throw a response code 400… to solve it:

<?php
try {
  $yt = new Zend_Gdata_YouTube();
  $videoEntry = $yt->getVideoEntry($key);
} catch(Zend_Gdata_App_HttpException e) {
  //handle error
}
?>