【问题标题】:How to move a google doc into a folder using Zend Gdata如何使用 Zend Gdata 将谷歌文档移动到文件夹中
【发布时间】:2012-06-04 16:27:53
【问题描述】:

嗨,伙计们,我真的很难使用 zend gdata 将文档从我的根文件夹移动到另一个文件夹,这是我正在尝试的方法,但它不起作用。

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($gUser, $gPass, $service);
$link = "https://docs.google.com/feeds/documents/private/full/spreadsheet:0AUFNVEpLOVg2U0E"; // Not real id for privacy purposes
$docs = new Zend_GData_Docs($client);

// Attach a category object of folder to this entry
// I have tried many variations of this including attaching label categories
$cat = new Zend_Gdata_App_Extension_Category('My Folder Name','http://schemas.google.com/docs/2007#folder');

$entry = $docs->getDocumentListEntry($link);
$entry->setCategory(array($cat));

$return = $docs->updateEntry($entry,$entry->getEditLink()->href);

当我运行此程序时,我得到 No errors,但似乎没有任何变化,并且返回数据不包含新类别。

编辑: 好的,我意识到它不是类别,而是决定资源所属的“集合”(文件夹)的链接。 https://developers.google.com/google-apps/documents-list/#managing_collections_and_their_contents 表示每个资源都有 as et of parent 链接,所以我尝试将代码更改为设置链接而不是设置类别,但这不起作用。

$folder = "https://docs.google.com/feeds/documents/private/full/folder%3A0wSFA2WHc";
$rel = "http://schemas.google.com/docs/2007#parent";

$linkObj = new Zend_Gdata_App_Extension_Link($folder,$rel,'application/atom+xml', NULL,'Folder Name');
$links = $entry->getLink();
array_push($links,$linkObj);
$entry->setLink($links);

$return = $docs->updateEntry($entry,$entry->getEditLink()->href);

编辑:[几乎]解决 好的这是如何从一个文件夹移动/复制到另一个文件夹: 比最初想象的要简单,但问题是它创建了一个参考而不是移动!它现在同时在两个地方....

// Folder you want to move too
$folder = "https://docs.google.com/feeds/folders/private/full/folder%asdsad";
$data = $docs->insertDocument($entry, $folder); // Entry is the entry you want moved using insert automatically assigns link & category for you...

【问题讨论】:

  • 第一件事:Zend_Gdata 类不是最新的,它们在developers.google.com/google-apps/documents-list/v2/… 使用 v2 api,您提供的链接是针对 v3 api 的。
  • 是的,我知道这一点,但该链接是我目前必须继续阅读的唯一文档,我必须尝试弄清楚如何去做,api 仍然使用 atom所以它仍然可以正常工作,它只是谷歌的文档信息太少了,即使是论坛也有很多关于如何做到这一点的问题没有任何令人满意的答案...groups.google.com/forum/embed/?place=forum/…。我确实意识到 Zend Gdata 较旧,但它可以做其他所有事情,只是移动似乎是个问题。
  • 我想你只需要做两个操作,在新文件夹中创建文件,然后从旧文件夹中删除文件。见developers.google.com/google-apps/documents-list/v2/… ...祝你好运
  • 是的,尝试过问题出在同一个文件上,所以当我删除它时,它会同时删除这两个文件,因为它们具有相同的 ID,只是不同的父级,v3 文档说这是可能的,“集合允许资源以保持彼此之间的“多对多”关系。”不确定这是否适用于条目,但假设确实如此。

标签: zend-framework gdata gdata-api zend-gdata


【解决方案1】:

要将文件复制/移动到文件夹中,请执行以下操作:

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($gUser, $gPass, $service); 
$docs = new Zend_GData_Docs($client);

$link = "https://docs.google.com/feeds/documents/private/full/spreadsheet:0AUFNVEpLOVg2U0E";
$entry = $docs->getDocumentListEntry($link);
// Folder (Collection you want to move to)
$folder = "https://docs.google.com/feeds/folders/private/full/folder%asdsad";
// Move
$data = $docs->insertDocument($entry, $folder);

现在有些问题是:

  1. 似乎只制作了reference副本,这意味着它仍然是同一个文档,只是它有一个额外的类别和父链接(所以它现在在两个地方)。这可以更好地解释它:https://groups.google.com/forum/embed/?place=forum/google-documents-list-api#!topic/google-documents-list-api/OrLi2JCINw4

我确信一定有办法让它“更干净”/更好,但至少它现在可以移动它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多