SmartDroidDeveloper / google-api-java-client

Automatically exported from code.google.com/p/google-api-java-client
0 stars 0 forks source link

Create a google doc document and change the content #161

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Which API and version (e.g. Google Calendar Data API version 2)?
Google Docs
2

What format (e.g. JSON, Atom)?
any

What Authentation (e.g. OAuth, OAuth 2, Android, ClientLogin)?
OAuth

Java environment (e.g. Java 6, Android 2.3, App Engine 1.4.2)?
Java 6 and Android

External references, such as API reference guide?

Please provide any additional information below.
How to post changes or create to a document (plain text) either exporting a 
file or editing.

gdata is straight forward on doing this, but google-api-java leaves me going 
around in circles over the documentation.  The documen

Original issue reported on code.google.com by jeremyvillalobos on 24 Mar 2011 at 6:06

GoogleCodeExporter commented 9 years ago
I  need the sample in Atom, I did not know enough about the difference 
yesterday.  

Original comment by jeremyvillalobos on 25 Mar 2011 at 2:59

GoogleCodeExporter commented 9 years ago
Nevermind. I got it.  First, I did not know enough about http protocol and that 
was part of the problem.  second the documentation in.

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

can be adapted to google-api-java client by understanding that the POST and 
non-xml lines at the beginning of packets are input information for 
GoogleHeaders.  I am using docs-v3-atom-oauth-sample as reference.

The xml atom information or file's content goes into an InputStreamContent that 
is then given to the request object (request.content).  for example:
//
//all these attributes have their respective variable in GoogleHeaders Object
//the authorization value is filled in existing sample code.
//
POST /feeds/default/private/full HTTP/1.1
Host: docs.google.com
GData-Version: 3.0
Authorization: <your authorization header here>
Content-Length: 73612
Content-Type: multipart/related; boundary=END_OF_PART
Slug: test.doc
//the content from here down can is given using an InputContentStream (refer to 
the only google docs sample to see how it works)
--END_OF_PART
Content-Type: application/atom+xml

<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns="http://www.w3.org/2005/Atom" 
xmlns:docs="http://schemas.google.com/docs/2007">
  <category scheme="http://schemas.google.com/g/2005#kind"
      term="http://schemas.google.com/docs/2007#document"/>
  <title>example document</title>
  <docs:writersCanInvite value="false" />
</entry>

Now, the only question I have is how do you input both Atom-xml information 
(metadata) and document content ( plain text for example) ?  this is not clear 
to me from the existing documentation.

Attached are the two methods to get a text file from docs, and to update the 
plain/text document.  You can add them to docs-v3-atom-oauth-sample.  

Original comment by jeremyvillalobos on 1 Apr 2011 at 2:47

Attachments: