topless
topless

Reputation: 8221

How can I use the OAuth2Decorator with Google Cloud Storage?

I am following this instructions in order to connect my app engine python web service with Google storage and specifically to be able to use files API. I went through the buzz example but doesn't seem to work for me. I need the web service to authorize in the background in order to be able to retrieve my files from storage.

I am trying to use the decorator in order to pass my client_id and client_secret but the process is not quite clear to me. Someone who can provide an example or elaborate a bit in the process?

edit: I am using python 2.7 runtime.

Upvotes: 1

Views: 1042

Answers (3)

topless
topless

Reputation: 8221

I managed to get it running properly by using the gslite.py script from the au-to-do google appengine project with my credentials.

Upvotes: 1

Greg
Greg

Reputation: 2609

If you are using the apiclient along with the native REST API, it would look something like this...

from apiclient.discovery import build
import httplib2
from oauth2client.appengine import OAuth2Decorator

decorator = OAuth2Decorator(client_id=YOUR_GOOGLE_CLIENT_ID,
                            client_secret=YOUR_GOOGLE_CLIENT_SECRET,
                            scope=GOOGLE_SERVICE_SCOPE,
                            )

class MainHandler(webapp.RequestHandler):

   @decorator.oauth_required
   def get(self):
    service = build(SERVICE_NAME, 
                    SERVICE_VERSION,
                    http=decorator.http())
    magic = service.method()

It might help to look at some of the apiclient examples for other APIs. For example, there's a nice example of an App Engine integration with the Tasks API that also uses OAuth2.

http://code.google.com/appengine/articles/python/getting_started_with_tasks_api.html

Upvotes: -1

Greg
Greg

Reputation: 2609

This may not be the most direct answer, but have you explored the built in Google Storage API on App Engine?

http://code.google.com/appengine/docs/python/googlestorage/

This lets you bypass the native API all together.

Upvotes: 1

Related Questions