使用 Zend Gdata Google Docs API 复制文档



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

有以下代码正在访问文档列表并允许我检索各个条目。

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

谷歌文档 API 链接https://developers.google.com/google-apps/documents-list/#copying_documents

以下是我的做法:(电子表格)

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

就是这样 - 为我工作!灵感来自 如何使用 Zend GData 创建空电子表格 [gaetan-frenoy]

相关内容

  • 没有找到相关文章

最新更新