[英]Delete document from Google Docs using Zend Gdata
I am having trouble working with Google Docs and Zend Framework 1.11.4. 我在使用Google Docs和Zend Framework 1.11.4时遇到麻烦。
What I am attempting to do is upload a document to Google Docs, retrieve the HTML content and delete the document. 我想做的是将文档上传到Google文档,检索HTML内容并删除该文档。 I am working with .doc, .pdf, and .rtf files.
我正在使用.doc,.pdf和.rtf文件。
My code so far: 到目前为止,我的代码:
$client = Zend_Gdata_ClientLogin::getHttpClient(
'my@googleDocsEmail.address',
'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();
Everything works fine until the ->delete() method is called, it returns an exception Expected response code 200, got 409 一切正常,直到调用-> delete()方法,它返回一个异常预期的响应代码200,得到409
I have been Googling this for a couple of days now but can find no answer, according to Googles documentation this is the correct way to delete a document. 我已经使用Google搜索了几天,但是找不到答案,根据Google的文档,这是删除文档的正确方法。
If anyone has any idea as to what I am doing wrong then any help would be very welcome. 如果有人对我做错了什么有任何想法,那么任何帮助都将非常受欢迎。
Many thanks in advance, Garry 提前非常感谢,加里
I was having the same 409 response issue when using the Zend_Gdata_Calendar library. 使用Zend_Gdata_Calendar库时,我遇到同样的409响应问题。 There is an open bug on the Zend framework bugtracker.
Zend框架Bugtracker上有一个未解决的错误。 See http://zendframework.com/issues/browse/ZF-10194
参见http://zendframework.com/issues/browse/ZF-10194
It seems to boil down to the lack of a "If-Match" header being set by the Gdata_App class or one of the child classes in the chain. 似乎归结为缺少由Gdata_App类或链中的子类之一设置的“ If-Match”标头。
To fix it for the Calendar API I've overridden the Zend_Gdata_Calendar class and instantiated my class instead of that one: 为了修复Calendar 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;
}
}
Then use it: 然后使用它:
...
$gdata = new Zend_Gdata_Calendar_Fixed($httpClient);
...
I imagine you could do the same thing but overriding the Zend_Gdata_Docs class instead. 我想您可以做同样的事情,但是要覆盖Zend_Gdata_Docs类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.