OAuth and text_db and google app engine and reading a google spreadsheet

286 views
Skip to first unread message

Ralph

unread,
Jul 5, 2009, 7:56:29 PM7/5/09
to GData Python Client Library Contributors, fed...@gmail.com
Hi,

I'm sure I'm missing something. But I don't see the correct way to
read a google spreadsheet from google app engine using OAuth.

Is there a simple example?

I can get the documents and spreadsheets names, dates, etc. but I
would like to access the data.


This is an example of reading a spreadsheet via installed app but I
want to do it from google app engine using OAuth.

Thanks.

import gdata.spreadsheet.text_db

client = gdata.spreadsheet.text_db.DatabaseClient
(username='X...@gmail.com',password='YYYY')
db = client.GetDatabases(name='My Tracks-street running')
table=db[0].GetTables()[0]
rows=table.GetRecords(1,1000)
for row in rows:
print row.content.get('name'),',', row.content.get('date'),',',
row.content.get('movingtime'),',', row.content.get('distance'),',',
row.content.get('distanceunit'),',', row.content.get('map')

for row in rows:
print '==='
for cell in row.content:
print '%s = %s' % (cell, row.content.get(cell), )

Jeff S (Google)

unread,
Jul 7, 2009, 1:18:01 PM7/7/09
to GData Python Client Library Contributors
Hi Ralph,

Since you are interested in using OAuth with App Engine, I recommend
starting with the following examples:

http://code.google.com/p/gdata-python-client/source/browse/#svn/trunk/samples/oauth/oauth_on_appengine
http://code.google.com/apis/gdata/oauth.html#Examples

Also, the text_db.DatabaseClient is slightly different than the other
service objects which are documented. It actually wraps two Service
classes, one to talk to Google Spreadsheets, and other to talk to
Google Documents (for creating spreadsheets). To set the auth token,
you need to set the OAuth access token on both objects. Here's an
incomplete example. but hopefully it will get the idea across:

client._GetDocsClient().SetOAuthToken(oauth_token)
client._GetSpreadsheetsClient().SetOAuthToken(oauth_token)

I recommend testing this as I'm not sure how many of the calls need to
be duplicated like this. Getting the token should require just one of
the sub clients (I'd probably use client._GetDocsClient() for
requesting the token and request a scope of both docs and
spreadsheets.) Once you have the access token, you would set it on
both clients.

In the future I plan to rewrite parts of the text_db module to use the
new feeds available in the API, and while we're at it I'll make sure
that this auth situation is cleaned up. This module was designed with
just the use of ClientLogin in mind, so while it is possible to use
AuthSub and OAuth, it feels a bit clunky.

Thank you,

Jeff


On Jul 5, 4:56 pm, Ralph <fed...@gmail.com> wrote:
> Hi,
>
> I'm sure I'm missing something.  But I don't see the correct way to
> read a google spreadsheet from google app engine using OAuth.
>
> Is there a simple example?
>
> I can get the documents and spreadsheets names, dates, etc. but I
> would like to access the data.
>
> This is an example of reading a spreadsheet via installed app but I
> want to do it from google app engine using OAuth.
>
> Thanks.
>
> import gdata.spreadsheet.text_db
>
> client = gdata.spreadsheet.text_db.DatabaseClient
> (username='...@gmail.com',password='YYYY')
Reply all
Reply to author
Forward
0 new messages