使用Zend Gdata Google Docs API复制文档

时间:2012-05-03 13:26:27

标签: google-api zend-gdata

我正在尝试确定如何使用Google Docs API Zend Gdata客户端制作文档副本。

我有以下代码访问DocumentList并允许我检索各个条目。

$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();
}

我正在尝试确定如何制作特定文档条目的副本,而无需下载然后重新上载。我知道它可以基于API文档来完成,但是.NET中给出的示例似乎没有很好地转换为PHP。

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

1 个答案:

答案 0 :(得分:0)

我是这样做的:(电子表格)

$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);

就是这样 - 适合我!灵感来自How to create an empty spreadsheet using Zend GData [gaetan-frenoy]