Gdata api 谷歌文档列表API-如何发布文档

Gdata api 谷歌文档列表API-如何发布文档,gdata-api,gdata,google-docs-api,put,zend-gdata,Gdata Api,Gdata,Google Docs Api,Put,Zend Gdata,我完全不知道如何以编程方式发布Google文档(特别是电子表格) 我已经阅读了Google Documents List API协议指南,并发现: 本文的下一节以“通过发布单个版本发布文档”开始,我在这里找到了以下示例: PUT /feeds/default/private/full/resource_id/revisions/revision_number GData-Version: 3.0 Authorization: <your authorization header here

我完全不知道如何以编程方式发布Google文档(特别是电子表格)

我已经阅读了Google Documents List API协议指南,并发现:

本文的下一节以“通过发布单个版本发布文档”开始,我在这里找到了以下示例:

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&amp;revision=1"/>
  <link rel="alternate" type="text/html"
      href="https://docs.google.com/Doc?id=doc_id&amp;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>

有人能帮我吗?有人通过编程成功发布过谷歌文档吗?

我本人是Zend_Gdata的新手,但已成功上传到谷歌文档

我不知道这是否是你想要的,但这是我的代码:

$client = Zend_Gdata_ClientLogin::getHttpClient(
    'my@googleDocsEmail.address', 
    'MyPassword', 
    Zend_Gdata_Docs::AUTH_SERVICE_NAME
);
$gdClient = new Zend_Gdata_Docs($client);

 $newDocumentEntry = $gdClient->uploadFile(
    $file, 
    null, 
    null, 
    Zend_Gdata_Docs::DOCUMENTS_LIST_FEED_URI
);
我希望这有帮助


Garry

谷歌说putted数据是错误的,并用代码400回复您

尝试放置此代码

<?xml version='1.0' encoding='UTF-8'?>

以前

<entry  xmlns='http://www.w3.org/2005/Atom'...

好的。。。我从哪里开始

首先,你的URL是不正确的

你有

$putURL = "http://docs.google.com/feeds/default/private/full/spreadsheet:".$theId."/revisions/0";
你应该有

$putURL = "http://docs.google.com/feeds/default/private/full/$theId/revisions/0";
(如果使用“作为分隔符”,则可以省略.for串联)

现在还有其他问题,因为您正在手动创建一个xml条目

  • 您的授权标头丢失
  • 在XML中使用的是修订版1,但在URL中使用的是修订版/0
  • 值是手动编写的,我很确定您没有试图发布一个2年前的文件。和的相同
  • 必须与检索到的etag匹配,否则将无法执行任何PUT请求
  • 现在您可以手动更改这些值并分配变量,但我认为最好使用Zend GData结构化返回对象

    无论如何:

  • 从google检索要发布的文档
  • 找到正确的条目(在本例中为ID:$theId/revisions/1的条目)
  • 将文档:发布值属性更改为“true”
  • 发送带有修改条目的put请求

  • 假设文档已经创建并且文档id为XXXX,则该操作应该有效

    您需要做的是将带有特定标题的“PUT”请求和XML(描述文档的条目)作为主体发送到特定URL

    由于您没有更改文档的任何内容(仅元数据),因此您的目标URL将如下所示

    您需要做的第一件事是使用适当的Google服务进行身份验证

    $client = Zend_Gdata_ClientLogin::getHttpClient(GDOC_LOGIN, GDOC_PASS,'writely');
    
    使用返回的对象获取身份验证令牌

    $auth_token = $client->getClientLoginToken();
    
    在Zend/Gdata/App.php中,是一个帮助函数,用于执行PUT请求。 准备此方法的参数,如下所示

    $method = "PUT";
    $url ="https://docs.google.com/feeds/default/private/full/XXXX/revisions/0";
    $headers['GData-Version'] = '3.0';
    $headers['If-Match'] = '*';
    $headers['Authorization'] = "GoogleLogin auth = $auth_token";
    $headers['Content-Length'] = '380';
    $headers['Content-Type'] = 'application/atom+xml';
    $body = <<<XML
    <?xml version='1.0' encoding='UTF-8'?>
    <entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007"
        xmlns:gd="http://schemas.google.com/g/2005">
      <category scheme="http://schemas.google.com/g/2005#kind"
          term="http://schemas.google.com/docs/2007#spreadsheet"/>
        <docs:publish value="true"/>
        <docs:publishAuto value="true"/>
    </entry>
    XML;
    $contentType = "application/atom+xml";
    $remainingRedirects = 99;
    
    祝你好运!
    让我知道这是否有帮助!

    他想发布一个现有的谷歌文档,而不是上传一个新文档。^^谢谢你的回复。你能详细说明并提供一个工作示例吗?我现在收到一个无效的请求URI错误。谢谢!这让我99%的时间都在那里。我收到一个文档id错误,但文档是错误的吴出版。
    $auth_token = $client->getClientLoginToken();
    
    $method = "PUT";
    $url ="https://docs.google.com/feeds/default/private/full/XXXX/revisions/0";
    $headers['GData-Version'] = '3.0';
    $headers['If-Match'] = '*';
    $headers['Authorization'] = "GoogleLogin auth = $auth_token";
    $headers['Content-Length'] = '380';
    $headers['Content-Type'] = 'application/atom+xml';
    $body = <<<XML
    <?xml version='1.0' encoding='UTF-8'?>
    <entry xmlns="http://www.w3.org/2005/Atom" xmlns:docs="http://schemas.google.com/docs/2007"
        xmlns:gd="http://schemas.google.com/g/2005">
      <category scheme="http://schemas.google.com/g/2005#kind"
          term="http://schemas.google.com/docs/2007#spreadsheet"/>
        <docs:publish value="true"/>
        <docs:publishAuto value="true"/>
    </entry>
    XML;
    $contentType = "application/atom+xml";
    $remainingRedirects = 99;
    
    $app = new Zend_Gdata_App();
    $app->performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);