使用 Zend GData 从垃圾箱恢复 Google 文档

发布于 2024-12-07 11:58:53 字数 563 浏览 0 评论 0原文

我正在创建一个使用 Google 文档进行存储的文件管理器,但我很难弄清楚如何恢复已发送到垃圾箱的文件。我可以使用此代码发送到垃圾箱:

$resourceId = "file:12345";
$link = "https://docs.google.com/feeds/default/private/full/";
$file = $docs->getDocumentListEntry($link.$resourceId);
$file->delete();

然后我可以使用以下方式查看所有已垃圾文件:

$docs = new Zend_Gdata_Docs($client);
$docs->setMajorProtocolVersion(3);
$feed = $docs->getDocumentListFeed($link."-/trashed");

foreach($feed->entries as $entry) {
  ...
}

我的问题是,我如何才能将这些文件之一恢复到删除之前的位置,就像在 Google 文档中一样?

I am creating a filemanger that uses Google Docs for storage, but I am having difficulty working out how to restore a file that has been sent to the trash. I can send to trash by using this code:

$resourceId = "file:12345";
$link = "https://docs.google.com/feeds/default/private/full/";
$file = $docs->getDocumentListEntry($link.$resourceId);
$file->delete();

I can then view all trashed documents using:

$docs = new Zend_Gdata_Docs($client);
$docs->setMajorProtocolVersion(3);
$feed = $docs->getDocumentListFeed($link."-/trashed");

foreach($feed->entries as $entry) {
  ...
}

My question is how can I then restore one of these files back to location it was before it was deleted as you can in Google Docs proper?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

喜你已久 2024-12-14 11:58:53

好的,我弄清楚了如何在我的 Google 文档应用程序中恢复已删除的文件。代码如下:

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($gUser, $gPass, $service);
$client->setHeaders('If-Match: *');
$gdocs = new Zend_GData_Docs($client);
$gdocs->setMajorProtocolVersion(3);

$slug = array('If-Match'=>'*'); 

$link = "https://docs.google.com/feeds/default/private/full/".$resourceId;
$entry = $gdocs->getDocumentListEntry($link);
$xml = $entry->getXML();
$feed = str_replace('label="trashed"', 'label=""',$xml);

$entryResult = $gdocs->updateEntry($feed, $entry->getEditLink()->href,null,$slug);

这也适用于取消文档和其他类别元素的星号。例如:

替换:

$feed = str_replace('label="trashed"', 'label=""',$xml);

为:

$feed = str_replace('label="starred"', 'label=""',$xml);

Ok, so I worked out how to restore trashed files in my Google Docs App. Code is as follows:

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($gUser, $gPass, $service);
$client->setHeaders('If-Match: *');
$gdocs = new Zend_GData_Docs($client);
$gdocs->setMajorProtocolVersion(3);

$slug = array('If-Match'=>'*'); 

$link = "https://docs.google.com/feeds/default/private/full/".$resourceId;
$entry = $gdocs->getDocumentListEntry($link);
$xml = $entry->getXML();
$feed = str_replace('label="trashed"', 'label=""',$xml);

$entryResult = $gdocs->updateEntry($feed, $entry->getEditLink()->href,null,$slug);

This will also work for unstarring a document and with other category elements. So for example:

Replace:

$feed = str_replace('label="trashed"', 'label=""',$xml);

With:

$feed = str_replace('label="starred"', 'label=""',$xml);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文