0

I have a server program that is trying to read a particular file from Google Drive. Authentication is set up using a service account, and can successfully perform admin SDK operations. However, then I try to use the Drive API in the following way, I get a 404 error:

credentials = SignedJwtAssertionCredentials(settings.GOOGLE_SERVICE_ACCOUNT_EMAIL, key, scope='https://www.googleapis.com/auth/drive')
http = credentials.authorize(httplib2.Http())
drive = build('drive', 'v2', http=http)
file_data = drive.files().get_media(fileId="MYFILEID").execute()

If I set the file permissions to 'anyone with the link can view' then the code works as expected.

The Drive API is enabled for the service account in the console, and the service account has been granted domain-wide delegation.

If I add sub='email@mydomain.com' to the SignedJwtAssertionCredentials call, then when I try to build the drive service I get an

AccessTokenRefreshError: access_denied

Any ideas?

EDIT:

If I share the file in question with the service account email address, it works. However, I would have thought that domain-wide delegation would provide domain-wide privileges. Is this the expected behaviour (i.e. service accounts can only access drive objects that are public/domain-wide or have been explicitly shared with the service account email)?

askvictor
  • 3,621
  • 4
  • 32
  • 45
  • Check this [SO question](http://stackoverflow.com/questions/22230567/google-python-admin-sdk-using-oauth2-for-a-service-account-education-edition) if it can help you :) – KENdi Mar 22 '16 at 07:02
  • thanks @KENdi - I had seen that one, and it helped me get to this stage. – askvictor Mar 23 '16 at 01:26

0 Answers0