'I am looking for Google drive storage size of the users associated with university email/directory api

I'm looking for a Google API to get the size of the drive of the users associated with university email/directory api, but I can't find anything. The code to delete a user's email using the Google API is provided below. Similarly, I need to know the size of the user's drive. Could someone please assist me? Is there a way to get the drive's size via an API? Thanks.

from __future__ import print_function

import os.path

from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build

# If modifying these scopes, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/admin.directory.group', 'https://www.googleapis.com/auth/admin.directory.user']



def main():
    """Shows basic usage of the Admin SDK Directory API.
    Prints the emails and names of the first 10 users in the domain.
    """
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first
    # time.
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    service = build('admin', 'directory_v1', credentials=creds)

    return service

def test():
    # user = service.users().get(userKey="[email protected]").execute()
    # members = service.groups().list(domain='my.csun.edu', userKey=user['primaryEmail'], pageToken=None, maxResults=500).execute()

    # print(user)

    # Call the Admin SDK Directory API
    print('Getting the first 10 users in the domain')
    results = service.users().list(customer='my_customer', maxResults=10,
                                   orderBy='email').execute()
    print(results)
    users = results.get('users', [])

    if not users:
        print('No users in the domain.')
    else:
        print('Users:')
        for user in users:
            print(user)
            # print(dir(user))
            # print(u'{0} ({1})'.format(user['primaryEmail'],
            #                           user['name']['fullName']))

def del_user(user):
    try:
        service.users().delete(userKey=user).execute()
        print("Deleted!")
    except:
        print("User doesn't exist!")

if __name__ == '__main__':
    service = main()
    nameExt='23'
    # with open('NewGmailInProd/gmailUser'+nameExt+'.txt') as fileToRead:
    # with open('NewGmailInProd/test.txt') as fileToRead:
    #     emails = fileToRead.readlines()
    emails = ['[email protected]']
    for email in emails:
        del_user(email.strip())


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source