Last active
August 11, 2016 08:13
-
-
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
This file contains 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 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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@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)