Created
March 27, 2019 00:45
-
-
Save DazWilkin/dca8c3db8879765632d4c4be8d662074 to your computer and use it in GitHub Desktop.
Stackoverflow #55345991
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from googleapiclient.discovery import build | |
from oauth2client.service_account import ServiceAccountCredentials | |
SERVICE_ACCOUNT_EMAIL = '[[ROBOT]]@[[PROJECT]].iam.gserviceaccount.com' | |
SERVICE_ACCOUNT_FILE_PATH = './credentials.json' | |
USER_EMAIL = '[email protected]' | |
def main(): | |
credentials = ServiceAccountCredentials.from_json_keyfile_name( | |
SERVICE_ACCOUNT_FILE_PATH, | |
scopes=['https://www.googleapis.com/auth/admin.directory.user'] | |
) | |
credentials = credentials.create_delegated(USER_EMAIL) | |
service = build('admin', 'directory_v1', credentials=credentials) | |
print('Getting the first 10 users in the domain') | |
results = service.users().list(customer='my_customer', maxResults=10, | |
orderBy='email').execute() | |
users = results.get('users', []) | |
if not users: | |
print('No users in the domain.') | |
else: | |
print('Users:') | |
for user in users: | |
print(u'{0} ({1})'.format(user['primaryEmail'], | |
user['name']['fullName'])) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment