How to move a google doc into a folder using Zend Gdata
Posted
by
Andre
on Stack Overflow
See other posts from Stack Overflow
or by Andre
Published on 2012-05-30T12:25:02Z
Indexed on
2012/06/03
10:41 UTC
Read the original article
Hit count: 345
Hi Guys I am really struggling with moving a document from my root folder to another folder using zend gdata here is how i am trying to do it, but its not working.
$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);
When I run this I get No errors, but nothing seems to change, and the return data does not contain the new category.
EDIT: Ok I realised that its not the category but the link that decides which "collection" (folder) a resource belongs too. https://developers.google.com/google-apps/documents-list/#managing_collections_and_their_contents says that each resource has as et of parent links, so I tried changing my code to do set link instead of set category, but this did not work.
$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);
EDIT: SOLVED [nearly] OK Here is how to move/copy, sort of, from one folder to another: simpler than initially thought, but problem is it creates a reference and NOT a move! It now in both places at the same time....
// Folder you wnat 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...
© Stack Overflow or respective owner