Reputation: 9440
I want to use the Google Drive API in my application. I signed up for a brand new Gmail address, went to the developers' console and created a project, and a service account for that project. I downloaded the credentials Json file, and added it to my project. I created a top-level Test folder
for testing my code.
My code works fine, in that I can get a list of the folders and files, create new folders, upload files, etc.
If I go to the UI for Google Drive, I can see the files and folders (all but two files deleted to simplify debugging). ..
My Drive
- Test folder
- 20,480 byte Word file
- Subfolder
- 69 byte text file
If I look at the files and folders from my code (via the API), I can also see them all.
If I use the About API Explorer to see how much disk space I've used, the usage is shown as 20480, ie just the Word file. However, if I call the About API from my code, the usage is 69 bytes, ie just the text file. I'm puzzled why each method includes just one file, rather than both methods taking both into account.
A possible clue is if I look in the User.PermissionId
property of the About
object, I see different values when called from the API explorer and when called from my code. This makes me wonder if I'm using two different accounts. However, I don't see how that can be, because I only have the one service account for this Gmail account. If the service account were different from the main Gmail account, then I wouldn't expect to see the files and folders that my code created when I look in the Drive UI.
Anyone able to explain what is going wrong here? Thanks
Upvotes: 1
Views: 107
Reputation: 116918
A service account is no you. A service account has its own google drive account and that is what you are interacting with.
So by doing about.get you are finding the information about the service accounts drive account. This is how much space it has.
When you shard a folder on your personal drive account with the service account it grants access to the folder. It can read from it but it does not own those files you do and they are currently residing on your personal drive account.
If you create a folder on the service accounts drive account, and upload something to that then you will see a change in about.get because you are using the service accounts storage.
Upvotes: 1
Reputation: 5533
When you use a Service Account to access the Drive API, it will use the Service Account credentials which points the Drive API to make operations in the Service Account drive rather than your drive. But there are other ways you can access your Drive using API:
Upvotes: 2