0

I am trying to determine how I can make a copy of a document using the Google Docs API Zend Gdata client.

I have the following code which is accessing the DocumentList and allows me to retrieve the individual entries.

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;

$sourceClient = Zend_Gdata_ClientLogin::getHttpClient($sourceUser, $sourcePass, $service);

$sourceDocs = new Zend_Gdata_Docs($sourceClient);

$entry = new Zend_Gdata_Docs_DocumentListEntry();

$docfeed = $sourceDocs->getDocumentListFeed();

foreach ($docfeed->entries as $entry)
{
      $entry->getTitleValue();
}

I am trying to determine how I can make a copy of a particular document entry without having to download it and then reupload it. I know it can be done based on the API Documentation, but the example is given in .NET which doesn't seem to translated into PHP very well.

Google Docs API Link https://developers.google.com/google-apps/documents-list/#copying_documents

1 Answers1

0

Here is how I did it: (spreadsheets)

$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$sourceClient = Zend_Gdata_ClientLogin::getHttpClient($sourceUser, $sourcePass, $service);
$connection = new Zend_Gdata_Spreadsheets($sourceClient);

// Get the Id of a sheet you want to copy [ensure its an object]
$titleOfSheetToCopy = 'CopyMe';
$feed = $connection->getSpreadsheetFeed();
foreach($feed as $entry) {
  if($entry->getTitle() == $titleOfSheetToCopy) {
    // this is a url string so you need to clean it
    $data = (string)$entry->getId();
    $data = explode("/",$data);
    $id = array_pop($data);
  }
}

// Create blank Entry Object       
$blankEntry = new Zend_Gdata_Spreadsheets_SpreadsheetEntry();

// Set title
$blankEntry->setTitle(new Zend_Gdata_App_Extension_Title("My new spreadsheet", null));

// Set the id to the id of the sheet you want to copy (we got that above)
$blankEntry->setId(new Zend_Gdata_App_Extension_Id($id);

That's it - Works for me! Inspired by How to create an empty spreadsheet using Zend GData [gaetan-frenoy]

Community
  • 1
  • 1
Andre
  • 2,449
  • 25
  • 24