0

I'm trying use google drive api. I created a service account credentials and downloaded from console cloud. The problem is that I'm part of an organization in gsuit and when I try list my files, it's empty, but I have files in my drive.

from apiclient.discovery import build
from oauth2client.service_account import ServiceAccountCredentials

credentials = ServiceAccountCredentials.from_json_keyfile_name(
    "credentials.json", scopes=['https://www.googleapis.com/auth/drive'])
service = build('drive', 'v3', credentials=credentials)
print(service.files().list().execute())

What could be?

ivan_filho
  • 1,371
  • 1
  • 10
  • 13
  • 1
    https://stackoverflow.com/questions/45492703/google-drive-api-oauth-and-service-account . The problem was that service account has it's own drive space. – ivan_filho Jun 11 '20 at 21:33

1 Answers1

1

Actually you are not providing a lot of information but make sure on the api credentials you issued you selected the 'Other UI' option on the field 'Where will you be calling the API from' and you chose 'User data' instead of 'Application data', also the scope should be 'https://www.googleapis.com/auth/drive.readonly.metadata' for listing data. 'https://www.googleapis.com/auth/drive' is correct too but given that it is a gsuite account there can be limitations on generic scopes even for your own data.

Also you should do service = DRIVE.files().list().execute().get('files', []) for f in files: print(f['name']) and enumerate that files array to get the files.

if that doesn't work have a look at the api docs and if you can't figure it out please post more details and try to do some debugging and post the results here.

Edit: Try using the restapi too with the appropriate credentials and see if the files are fetched successfully there. https://developers.google.com/drive/api/v2/reference/files/list

  • Maybe the problem is this: https://stackoverflow.com/questions/45492703/google-drive-api-oauth-and-service-account but I can't see files even sharing with service account email – ivan_filho Jun 11 '20 at 19:34