Seeking python example.

43 views
Skip to first unread message

codingJoe

unread,
Nov 23, 2009, 3:08:18 PM11/23/09
to Google Documents List API
All,

If I create a folder, how can I save a reference to that folder and
then later recreate the folder object to do things like MoveIntoFolder
(...)

I'm doing this on GAE using the db.Model. I am able to stuff the
folderID into a string, but I have no idea how to turn that string
back into a folder reference.

Any code snippets are greately appreciated!!

-Joe

Eric Bidelman

unread,
Nov 23, 2009, 3:29:48 PM11/23/09
to google-docum...@googlegroups.com
Using the new v3.0 classes:

saved_resource_id = 'folder%3A0B9kVjMzJkNjYz'
folder_entry = client.GetDoc(saved_resource_id)

In the old classes, try my response here:

Eric

codingJoe

unread,
Nov 24, 2009, 12:56:37 AM11/24/09
to Google Documents List API
Thanks for the snippet, it was a good start point. I'm having a few
issues grabbing that folder object. Am I doing this correctly?
Advice?

#The folder I want to get
logging.debug("want to grab folder: " + root_folder)
# prints: want to grab folder: folder:
0BxnrF1v7z5alNmI5OTJhMzItYTA1YS00MDZjLWFiNjEtNmExMjFiMTAxMTRl

# TRY 1
folder_entry = docClient.GetDoc(root_folder)
# Fails: folder_entry = docClient.GetDoc(root_folder)
# AttributeError: 'DocsService' object has no attribute
'GetDoc'

# TRY 2: I must have the old classes
uri = 'http://docs.google.com/feeds/documents/private/full/' +
root_folder
folder_entry = docClient.Query(uri,
converter=gdata.docs.DocumentListEntryFromString)
root_entry = docClient.Query(folderURI,
converter=gdata.docs.DocumentListEntryFromString)
# FAILS:
# File "/cygdrive/e/project_was/gdata/docs/service.py", line
218, in Query
# return self.Get(uri, converter=converter)
# ...
# return converter(result_body)
# File "/cygdrive/e/project_was/gdata/docs/__init__.py", line
190, in DocumentListEntryFromString
# return atom.CreateClassFromXMLString(DocumentListEntry,
xml_string)
# File "/cygdrive/e/project_was/atom/__init__.py", line 93,
in optional_warn_function
# return f(*args, **kwargs)
# File "/cygdrive/e/project_was/atom/__init__.py", line 128,
in CreateClassFromXMLString
# tree = ElementTree.fromstring(xml_string)
# File "<string>", line 85, in XML
# SyntaxError: not well-formed (invalid token): line 154,
column 60


# TRY 3: long shot - even tried to urlencode: folder:
0BxnrF1v7z5alNmI.. since the ':' character may cause issues.
# FAILS same Error

On Nov 23, 1:29 pm, Eric Bidelman <api.e...@google.com> wrote:
> Using the new v3.0 classes:
>
> saved_resource_id = 'folder%3A0B9kVjMzJkNjYz'
> folder_entry = client.GetDoc(saved_resource_id)
>
> In the old classes, try my response here:http://groups.google.com/group/google-documents-list-api/browse_threa...
>
> Eric

Eric Bidelman

unread,
Nov 24, 2009, 11:27:46 AM11/24/09
to google-docum...@googlegroups.com
On Tue, Nov 24, 2009 at 12:56 AM, codingJoe <tracy.m...@gmail.com> wrote:
Thanks for the snippet, it was a good start point.  I'm having a few
issues grabbing that folder object.  Am I doing this correctly?
Advice?

    #The folder I want to get
    logging.debug("want to grab folder: " + root_folder)
    # prints: want to grab folder: folder:
0BxnrF1v7z5alNmI5OTJhMzItYTA1YS00MDZjLWFiNjEtNmExMjFiMTAxMTRl

This needs to be a resource id (that includes the type), so:
folder%3A0BxnrF1v7z5alNm...



    # TRY 1
    folder_entry = docClient.GetDoc(root_folder)
    # Fails:  folder_entry = docClient.GetDoc(root_folder)
    #         AttributeError: 'DocsService' object has no attribute
'GetDoc'

Looks like you haven't updated to the latest version of the source.
Check it out from SVN.  Here is the check-in:
Not sure on this one.  Try adding a print statement in 128 of atom/__init__.py
to see what XML you're getting at line 154, col 60.

codingJoe

unread,
Nov 25, 2009, 4:26:32 PM11/25/09
to Google Documents List API
Thanks for the pointer! I was able to get the latest svn python-
client.

Now trying to overcome some subtle differences like: SetAuthSubToken
is not defined. (See below for how I currently authenticate) How do
you authenticate with the new DocsClient?

The only example documentation I am aware is for the older
DocsService. http://code.google.com/apis/documents/docs/1.0/developers_guide_python.html

Is there a newer developers guide for python that I should be
referencing?

Thanks!

-Joe







def GetDocsClient(self, handler, scope):
user = users.get_current_user()
if user:
client = gdata.docs.service.DocsService()
#Porting code to use DocsClient not DocsService
#client = gdata.docs.client.DocsClient()
gdata.alt.appengine.run_on_appengine(client)
for token in StoredToken.gql('WHERE user_email = :1', user.email
()):
if scope.find(token.target_url) > -1:
client.SetAuthSubToken(token.session_token)
return client
if handler.request.get('token'):
token = handler.request.get('token')
if handler.request.get('auth_sub_scopes'):
scope = handler.request.get('auth_sub_scopes')
client.SetAuthSubToken(token)
client.UpgradeToSessionToken()
new_token = StoredToken(user_email=user.email(),
session_token=client.GetAuthSubToken
(),
target_url=scope)
new_token.put()
return client
else:
handler.redirect(client.GenerateAuthSubURL
(handler.request.uri,
scope, secure=False,
session=True,
domain=_hosted_domain).to_string())
else:
handler.redirect(users.create_login_url(handler.request.uri))

On Nov 24, 9:27 am, Eric Bidelman <api.e...@google.com> wrote:
> On Tue, Nov 24, 2009 at 12:56 AM, codingJoe <tracy.monte...@gmail.com>wrote:
>
> > Thanks for the snippet, it was a good start point.  I'm having a few
> > issues grabbing that folder object.  Am I doing this correctly?
> > Advice?
>
> >     #The folder I want to get
> >     logging.debug("want to grab folder: " + root_folder)
> >     # prints: want to grab folder: folder:
> > 0BxnrF1v7z5alNmI5OTJhMzItYTA1YS00MDZjLWFiNjEtNmExMjFiMTAxMTRl
>
> This needs to be a resource id (that includes the type), so:
> folder%3A0BxnrF1v7z5alNm...
>
> http://code.google.com/apis/documents/docs/3.0/developers_guide_proto...

Eric Bidelman

unread,
Nov 30, 2009, 11:58:09 AM11/30/09
to google-docum...@googlegroups.com
The docs need updating.  I'm actually working on that as we speak :)

If you already have a session token, you can use:
self.client.auth_token = gdata.gauth.AuthSubToken("TOKEN_VALUE")

The upgrade process is something like this (90% sure this is right):

# Fetch a new token for a Google Account
authsub_request_url = gdata.gauth.generate_auth_sub_url(
        next_url, ['http://docs.google.com/feeds'], secure=False,
        session=True, domain='default')

# Upgrade the token in the URL
token = gdata.gauth.AuthSubToken.FromUrl(self.request.uri)
session_token = client.UpgradeToken(token)

Do a help(gdata.docs.client.DocsClient) to see the available methods.

Cheers,
Eric

codingJoe

unread,
Nov 30, 2009, 11:26:30 PM11/30/09
to Google Documents List API
Thanks!! I look forward to the release of the new documentation when
its finished.

I am enthusiastic about integrating google docs into my process. I
will support end-user testing and debugging however possible. :)

-Joe

On Nov 30, 9:58 am, Eric Bidelman <api.e...@google.com> wrote:
> The docs need updating.  I'm actually working on that as we speak :)
>
> If you already have a session token, you can use:
> self.client.auth_token = gdata.gauth.AuthSubToken("TOKEN_VALUE")
>
> The upgrade process is something like this (90% sure this is right):
>
> # Fetch a new token for a Google Account
> authsub_request_url = gdata.gauth.generate_auth_sub_url(
>         next_url, ['http://docs.google.com/feeds'], secure=False,
>         session=True, domain='default')
>
> # Upgrade the token in the URL
> token = gdata.gauth.AuthSubToken.FromUrl(self.request.uri)
> session_token = client.UpgradeToken(token)
>
> Do a help(gdata.docs.client.DocsClient) to see the available methods.
>
> Cheers,
> Eric
>
> On Wed, Nov 25, 2009 at 1:26 PM, codingJoe <tracy.monte...@gmail.com> wrote:
> > Thanks for the pointer!  I was able to get the latest svn python-
> > client.
>
> > Now trying to overcome some subtle differences like: SetAuthSubToken
> > is not defined. (See below for how I currently authenticate)  How do
> > you authenticate with the new DocsClient?
>
> > The only example documentation I am aware is for the older
> > DocsService.
> >http://code.google.com/apis/documents/docs/1.0/developers_guide_pytho...
Reply all
Reply to author
Forward
0 new messages