I have a Google App Engine Python application with a lot of features. Now I want to integrate Google Drive into the application. In particular, I want my application to be able to:
- Create an empty file in my Google Drive, where my user can create a Google Doc.
- Get this file from Google Drive for further processing in my application.
- Submit it on Google Drive periodically so that the user can perform further editing on it as Google Doc.
I would be infinitely grateful if someone who knows how to do what I am trying to do can direct me to SPECIFIC Google web pages that meet my specific requirement (not a generic answer like: "See DrEdit example" ) Thanks in advance!
Update:
Based on the generated code sample in drive-v2-python-appengine on the sentence in answer 1, here is my program with RequestHandler to create an empty file:
import os import webapp2 import io from google.appengine.api import memcache import httplib2 from apiclient.discovery import build from apiclient.http import MediaIoBaseUpload from oauth2client.appengine import oauth2decorator_from_clientsecrets decorator = oauth2decorator_from_clientsecrets( os.path.join(os.path.dirname(__file__), 'client_secrets.json'), scope=[ 'https://www.googleapis.com/auth/drive', ]) http = httplib2.Http(memcache) drive_service = build("drive", "v2", http=http) class CreateEmptyFile(webapp2.RequestHandler): @decorator.oauth_required def get(self): body = { 'title': 'Sample Document', 'description': 'A sample document', 'mimeType': 'text/plain' } media_body = MediaIoBaseUpload(io.BytesIO(""), mimetype='text/plain', resumable=True) file = drive_service.files().insert(body=body, media_body=media_body).execute() self.redirect("/synopsis")
Testing is somewhat confusing, because sometimes when I ran this, including the first time, it raised the access request page, but most of the time it is not. I used https://accounts.google.com/b/0/IssuedAuthSubTokens?hl=en to revoke access to Drive and Drive no longer appears in the list, but I think that a time delay of an hour or more exists for access revocation . Not sure about this and have not seen documented.
In any case, if I comment out the drive_service.files().insert() call, it does not interrupt and is redirected to my synopsis page. I believe that this means that authorization works correctly, as this makes it look like the generated code sample.
However, if I do not comment on insert and use resumable=True for the media body, I get:
ResumableUploadError: Failed to retrieve starting URI.
And if I use resumable=False , I get:
HttpError: <HttpError 401 when requesting https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart&alt=json returned "Login Required">
So, I seem to be able to access OAuth 2.0 authorization, but cannot insert the file.