我完全不知道如何以编程方式发布 Google 文档(特别是电子表格)。
我已经阅读了 Google Documents List API 协议指南并发现了这一点:
http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#GettingRevisions
文章的下一部分以“通过发布单个修订来发布文档”开始,这就是我找到这个示例的地方:
PUT /feeds/default/private/full/resource_id/revisions/revision_number
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 722
Content-Type: application/atom+xml
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:gd='http://schemas.google.com/g/2005'
xmlns:docs="http://schemas.google.com/docs/2007" gd:etag="W/"DkIBR3st7ImA9WxNbF0o."">
<id>https://docs.google.com/feeds/id/resource_id/revisions/1</id>
<updated>2009-08-17T04:22:10.440Z</updated>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-06T03:25:07.799Z</app:edited>
<title>Revision 1</title>
<content type="text/html" src="https://docs.google.com/feeds/download/documents/Export?docId=doc_id&revision=1"/>
<link rel="alternate" type="text/html"
href="https://docs.google.com/Doc?id=doc_id&revision=1"/>
<link rel="self" type="application/atom+xml"
href="https://docs.google.com/feeds/default/private/full/resource_id/revisions/1"/>
<author>
<name>user</name>
<email>user@gmail.com</email>
</author>
<docs:publish value="true"/>
<docs:publishAuto value="false"/>
</entry>
我一直在检索文档列表提要和 CRUDing 工作表,但我无法让发布工作,也不了解它应该如何工作。我建立与我的提要的连接并准备要 PUT 的数据的基本设置如下:
<?php
set_include_path($_SERVER['DOCUMENT_ROOT'].'/library/');
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->setFallbackAutoloader(true);
$theId = 'my-worksheet-id';
$user = "my-gmail-account-name";
$pass = "my-gmail-account-password";
$service = Zend_Gdata_Docs::AUTH_SERVICE_NAME;
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
$service = new Zend_Gdata($client);
$xml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gd='http://schemas.google.com/g/2005'
xmlns:docs='http://schemas.google.com/docs/2007' gd:etag='W/\"DkIBR3st7ImA9WxNbF0o.\"'>
<id>https://docs.google.com/feeds/id/spreadsheet:$theId/revisions/1</id>
<updated>2009-08-17T04:22:10.440Z</updated>
<app:edited xmlns:app='http://www.w3.org/2007/app'>2009-08-06T03:25:07.799Z</app:edited>
<title>Revision 1</title>
<content type='text/html' src='https://docs.google.com/feeds/download/documents/Export?docId=$theId&revision=1'/>
<link rel='alternate' type='text/html'
href='https://docs.google.com/Doc?id=$theId&revision=1'/>
<link rel='self' type='application/atom+xml'
href='https://docs.google.com/feeds/default/private/full/spreadsheet:$theId/revisions/1'/>
<author>
<name>$user</name>
<email>$user</email>
</author>
<docs:publish value='true'/>
<docs:publishAuto value='false'/>
</entry>";
$putURL = "http://docs.google.com/feeds/default/private/full/spreadsheet:".$theId."/revisions/0";
$data = $service->put($xml, $putURL);
?>
这导致
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Invalid request URI
有人可以帮我吗?有没有人以编程方式成功发布了 Google 文档?