How to access the same files list through Google Drive's API as Google's API Explorer? How to access the same files list through Google Drive's API as Google's API Explorer? curl curl

How to access the same files list through Google Drive's API as Google's API Explorer?


It sounds like you have used a Service Account and so the credentials you are using and hence the one file you are seeing, belong to the Service Account, not your user account. Some ways to confirm:-

  1. Check the created date of the file. If it was the same date as you generated the credentials, it's a Service Account.
  2. Check the owner of the file.
  3. Get the About resource https://developers.google.com/drive/api/v3/reference/about

Unfortunately, the Google documentation leads people to conclude that Service Accounts are a convenient way to bypass OAuth in order to get to your files, whereas it should say in large red letter "SERVICE ACCOUNTS ARE NOT THE ACCOUNT YOU THINK THERE ARE!!!"

You have 2 choices:- 1. Share all the files you want to access with the Service Account 1. Stop using Service Accounts and follow the steps in the last link you posted (How do I authorise an app (web or installed) without user intervention?) to access your regular account directly


How to access the same files list through Google Drive's API as Google's API Explorer?

As you are using a service account this will be very hard. Service accounts are not you a service account is a dummy user that has its own google drive account. Currently its drive account only contains one file. "Getting Started".

Google apis explore allows you to login to your personal google drive account using Oauth2. This is a different authorization flow which requires that the user login to their google account and consent to the application accessing their data. This gives you access to your google drive account.

Service accounts are a different type of authorization flow. The credentials within the flow are used to login the service account user this can only be done server side. Service account authentication can not be done client side. The trick with service accounts is that they can be preauthorized. So you can grant the service account access to data and when it logs in it will not need to consent to the access as the normal Oauth2 flow does. So you can share files and directories on your personal google drive account with the service account. This is done by taking the service account email address and sharing a file or a directory with it like you would any other user. The service account will then have access to that file or directory.

Now for the reason why I said it will be hard to get the exact response that you would be getting from Google APIs explorer. It is not possible to share your root folder with anyone else. If you want the service account to have full access and the same response then you are going to have to share every directory in your root folder and every file in the root of your google drive account with the service account. Any new files or folders that you add you will have to share with the service account.