如何使用Zend Gdata将谷歌文档移动到文件夹中

时间:2012-05-30 12:25:02

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

嗨大家我真的很挣扎着使用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说每个资源都有父链接,所以我尝试更改代码来设置链接而不是设置类别,但这不起作用。

$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...

1 个答案:

答案 0 :(得分:0)

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

$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. 它似乎仅使引用副本,这意味着它仍然是相同的文档,只有它有一个额外的类别和父链接(因此它现在在两个地方)。这可以更好地解释:https://groups.google.com/forum/embed/?place=forum/google-documents-list-api#!topic/google-documents-list-api/OrLi2JCINw4
  2. 我确信必须有办法让它“更清洁”/更好,但至少现在它会移动它。