How to check remaining cloud storage space using Java Google Drive API

I’m working on a Java project that connects to Google Drive using their API. I went with the older version of the API instead of the newer one because it seemed easier to understand and implement.

Right now my application can do basic file operations like listing documents, uploading new files, downloading existing ones, and removing files I don’t need anymore. Everything works fine for these tasks.

But I need to add a feature that shows how much storage space is left in the user’s Google Drive account. Is there a way to get this information through the API? I want to display the remaining storage capacity to users before they try to upload large files.

The About resource approach works, but I hit a few gotchas. The storage values return as Long objects, so handle the response accordingly. Some personal accounts return null for certain fields - check for nulls or you’ll get exceptions. The API lags behind file operations, so don’t expect real-time storage updates after uploads/deletions. For production, cache storage info for a few minutes instead of hitting the API constantly. Saves on quotas and improves performance.

Use the About resource in Google Drive API to check remaining storage. Call about().get() with storageQuota in the fields parameter. You’ll get back the storage limit, total usage, and Drive-specific usage (usageInDrive). Just subtract usage from the limit to find available space. Keep in mind the quota covers Drive, Gmail, and Photos combined, so focus on the usageInDrive number for your needs. This method works well, but watch out for Google Workspace users who might have unlimited storage.

yep, the about endpoint is what ya need. but keep in mind, workspace accounts might show -1 for endless storage, so account for that in your code. also, make sure you’ve got the right oauth scopes set up or it won’t work properly.