3

How can I get the storage usage of Gmail programmatically? This value appears in two places, but I cannot find an API for it.

The main goal is to automatically log Gmail storage usage to a Google Sheet and graph the storage usage trend.

What I've tried:

  1. DriveApp.getStorageUsed() does not include Gmail usage.
  2. Reports API (gmail_used_quota_in_mb) is not available for consumer Gmail accounts (only G Suite)
  3. Scraping www.google.com/settings/u/0/storage is not possible because a log-in is required, even when spoofing cookies (probably detects a new device/IP address).

enter image description here

Kos
  • 4,890
  • 9
  • 38
  • 42
Leftium
  • 16,497
  • 6
  • 64
  • 99
  • I also can't find any documentation or examples using the API. You may file a [feature request](https://issuetracker.google.com/issues/new?component=191650&template=824106) regarding this. – abielita Jul 31 '17 at 15:35
  • @abielita See my response below. – Seyeong Jeong May 24 '20 at 11:51

2 Answers2

0

Not the programmatic answer I am looking for, but this is my manual work-around until I discover an API method:

  1. Examine the source code for google.com/settings/u/0/storage
  2. Find exact bytes of usage embedded in JSON:
...
,[["Drive",["24004828","0.02 GB"]
]
,["Gmail",["4859735562","4.52 GB"]
]
,["Google Photos",["0","0 GB"]
...
  1. Log that (4,859,735,562) into a Google Sheet, along with the current date/time

Using precise measurements of bytes and seconds, it should only take a few measurements to get an accurate trend. (And I don't need to scale this for multiple accounts.)

Leftium
  • 16,497
  • 6
  • 64
  • 99
0

You can use Google Drive V2 API.

About: get returns quotaBytesByService[] where you can filter service by name (e.g. GMAIL, in your case)

If you want to use the API, you have to enable the advance API option and use it.

Note that the version 3 does not give you the service breakdown.

Seyeong Jeong
  • 10,658
  • 2
  • 28
  • 39