2

I am trying to gain service account access to to the Google Drive API. I followed the Google Drive SDK example when I was building my application. My code resembles the example almost exactly:

class MainPage(webapp2.RequestHandler):
    def get(self):
      build = createDriveService(user)
      searchFile = build.files().get(fileId='FILEID').execute()
      self.response.write(searchFile)

def createDriveService(userEmail):
    API_KEY = 'APIKEY' 
    credentials = AppAssertionCredentials(
        scope='https://www.googleapis.com/auth/drive',
        sub=userEmail)
    http = httplib2.Http()
    http = credentials.authorize(http)

    return build('drive', 'v2', http=http, developerKey=API_KEY)

When I call visit my GAE page the error in the logs that I am getting is:

<"File not found: FILEID">

I know the file ID exists as I copied it from the UI. I am using the simple Key access for the variable API_KEY. Should I be validating my application a different way?

EDIT1:

I've tried following various other StackOverflow. One of which involves using the SignedJwtAssertionCredentials and converting the .p12 key to a .pem key. After this change I am getting a

 cannot import SignedJwtAsserionCredentials 

error. From there I made sure to include the pycrypto library in my app.yaml. Any Idea?

EDIT2

I have successfully impersonated users on app engine. I followed this previously answered question and it worked.

Community
  • 1
  • 1
Alex
  • 135
  • 2
  • 13

1 Answers1

0

I do not understand the user part of your code, bacause you use a Google App Engine project user account. See this doc on how to use and find this account. You can also fnd this account using :

from google.appengine.api import app_identity
logging.info('service account : ' + app_identity.get_service_account_name())

Make sure you have given this project user account access to your drive file or folder!

My code looks like this :

def createDriveService():

    SCOPE = 'https://www.googleapis.com/auth/drive'
    API_KEY = 'AIzaSyB9UkK4OH5Z_E4v3Qp6bay6QEgGpzou3bc'     # GAE
    credentials = AppAssertionCredentials(scope=SCOPE)
    logging.info('using service account : ' + app_identity.get_service_account_name())
    http = credentials.authorize(httplib2.Http())
    return build('drive', 'v2', http=http, developerKey=API_KEY) 
voscausa
  • 11,253
  • 2
  • 39
  • 67
  • The reason that the user is a variable in my code is because I am mirroring [this example](https://developers.google.com/drive/delegation) of how to use domain wide delegation and impersonate other users. – Alex Aug 12 '13 at 18:28
  • OK. I'am not familiair with this option. – voscausa Aug 12 '13 at 18:38
  • Also, when I used code, I received the same error (after changing the API Key) – Alex Aug 12 '13 at 18:39
  • When you use my code, did you add the service account to your file to give it access? – voscausa Aug 12 '13 at 18:48
  • Yes but that will not fit my use case. Thank you. Any insight into the user impersonation? Currently, I can run my program using SignedJwtAssertionCredentials from the terminal, but since I want the application to run on GAE, I cannot have a downloaded key. Any thoughts? – Alex Aug 12 '13 at 19:03