Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6163217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:47:18+00:00 2026-05-23T21:47:18+00:00

I’m utterly lost as to how one can programmatically publish a Google Document (specifically

  • 0

I’m utterly lost as to how one can programmatically publish a Google Document (specifically a spreadsheet).

I’ve read the Google Documents List API Protocol Guide and have found this:

http://code.google.com/apis/documents/docs/3.0/developers_guide_protocol.html#GettingRevisions

The next section of the article begins with ‘Publishing documents by publishing a single revision’ and this is where I found this example:

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>

I have been retrieving document list feeds and CRUDing worksheets but I cannot get the publishing to work nor do I understand how it is supposed to work. My basic setup for establishing a connection to my feed and preparing the data to be PUT is as follows:

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

Which results in a

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 400 Invalid request URI

Can someone help me out? Has anyone successfully published a Google Document programmatically?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:47:20+00:00Added an answer on May 23, 2026 at 9:47 pm

    Assuming the document has already been created and has a document id of XXXX

    What you need to do is send a “PUT” request with specific headers, and XML (an entry describing your document) as the body, to a specific URL.

    Since you are not changing any content of the doc (only the meta-data), your target URL will look like this…

    https://docs.google.com/feeds/default/private/full/XXXX/revisions/0

    The first thing you need to do is authenticate with the proper Google service.

    $client = Zend_Gdata_ClientLogin::getHttpClient(GDOC_LOGIN, GDOC_PASS,'writely');
    

    Use the returned object to grab your auth token.

    $auth_token = $client->getClientLoginToken();
    

    In Zend/Gdata/App.php is a helper function for executing the PUT request.
    Prepare parameters for this method like so…

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

    Then call the helper function…

    $app = new Zend_Gdata_App();
    $app->performHttpRequest($method, $url, $headers, $body, $contentType, $remainingRedirects);
    

    Good luck!
    Let me know if this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.