2011-04-20 70 views
1

我在使用Google文檔和Zend Framework 1.11.4時遇到問題。使用Zend Gdata從Google文檔中刪除文檔

我正在嘗試將文檔上傳到Google文檔,檢索HTML內容並刪除文檔。我正在使用.doc,.pdf和.rtf文件。

我迄今爲止代碼:

$client = Zend_Gdata_ClientLogin::getHttpClient(
    '[email protected]', 
    'MyPassword', 
    Zend_Gdata_Docs::AUTH_SERVICE_NAME 
); 
$gdClient = new Zend_Gdata_Docs($client); 

$newDocumentEntry = $gdClient->uploadFile(
    $file, 
    null, 
    null, 
    Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI 
); 

$cv = file_get_contents($newDocumentEntry->getContent()->getSrc()); 

$newDocumentEntry->delete(); 

一切工作正常,直到 - >刪除()方法被調用,它返回一個例外預期的響應碼200,有409

我一直根據Googles文檔,這是Google正確刪除文檔的一種方式,但現在幾天沒有找到答案。

如果任何人有任何想法,我做錯了什麼,那麼任何幫助將非常歡迎。

提前許多感謝, 加里

+0

409 CONFLICT - 指定的版本號與資源的最新版本號不匹配。認爲你必須「重新獲取」文檔(按ID搜索..) – opHASnoNAME 2011-04-21 12:59:31

+0

謝謝ArneRie,我會試試看。 – Garry 2011-04-22 22:17:33

+1

@ArneRie仍然沒有這樣的喜悅,會去找B計劃,直到找到答案。我已要求在[ZendCasts](http://www.zendcasts.com/forum/topic/345/zendgdata-google-docs/)上針對此主題進行屏幕演示, – Garry 2011-04-24 14:34:04

回答

0

使用Zend_Gdata_Calendar庫時,我也有同樣的409響應的問題。 Zend框架bugtracker上有一個開放的錯誤。請參閱http://zendframework.com/issues/browse/ZF-10194

似乎歸結爲缺少由Gdata_App類或鏈中的子類之一設置的「If-Match」標頭。

要解決它的日曆API,我已經覆蓋了Zend_Gdata_Calendar類實例化我的課,而不是一個:

class Zend_Gdata_Calendar_Fixed extends \Zend_Gdata_Calendar { 
    /** 
    * Overridden to fix an issue with the HTTP request/response for deleting. 
    * @link http://zendframework.com/issues/browse/ZF-10194 
    */ 
    public function prepareRequest($method, 
            $url = null, 
            $headers = array(), 
            $data = null, 
            $contentTypeOverride = null) { 
     $request = parent::prepareRequest($method, $url, $headers, $data, $contentTypeOverride); 

     if($request['method'] == 'DELETE') { 
      // Default to any 
      $request['headers']['If-Match'] = '*'; 

      if($data instanceof \Zend_Gdata_App_MediaSource) { 
       $rawData = $data->encode(); 
       if(isset($rawData->etag) && $rawData->etag != '') { 
        // Set specific match 
        $request['headers']['If-Match'] = $rawData->etag; 
       } 
      } 
     } 
     return $request; 
    } 
} 

然後使用它:

... 
$gdata = new Zend_Gdata_Calendar_Fixed($httpClient); 
... 

我想你可以做相同的事情,但重寫Zend_Gdata_Docs類。