Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MeLight/1f4517560a9761317d13ebb2cdc670d3 to your computer and use it in GitHub Desktop.
Save MeLight/1f4517560a9761317d13ebb2cdc670d3 to your computer and use it in GitHub Desktop.
Using the updated oauth2client library to get delegated domain access by the means of ServiceAccountCredentials
from oauth2client.service_account import ServiceAccountCredentials
import httplib2
from googleapiclient import discovery
import oauth2client
def main():
"""Shows basic usage of the Google Admin SDK Directory API.
Creates a Google Admin SDK API service object and outputs a list of first
10 users in the domain.
"""
credentials = ServiceAccountCredentials.from_json_keyfile_name('qa-app-key.json', scopes=[
'https://www.googleapis.com/auth/admin.directory.user',
])
credentials = credentials.create_delegated('admin@of-a-connected-domain.com')
http = credentials.authorize(httplib2.Http())
service = discovery.build('admin', 'directory_v1', http=http)
print('Getting the first 10 users in the domain')
results = service.users().list(customer='my_customer', orderBy='email').execute()
if __name__ == '__main__':
main()
@dhermes
Copy link

dhermes commented Aug 11, 2016

@MeLight you'd get syntax highlighting if you renamed the file with a .py extension (or if you manually asked the gist for Python syntax highlighting)

@MeLight
Copy link
Author

MeLight commented Aug 11, 2016

@dhermes thanks for the tip. Updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment