Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Created November 10, 2015 21:54
Show Gist options
  • Save gene1wood/3aaecf95e4369d947129 to your computer and use it in GitHub Desktop.
Save gene1wood/3aaecf95e4369d947129 to your computer and use it in GitHub Desktop.
Example code to create a Google group (which I don't have authorization to run)
from oauth2client.client import SignedJwtAssertionCredentials
import json
from httplib2 import Http
from apiclient.discovery import build
with open('AWS Security Email Group-1f0fae884116.json', 'r') as f:
credential_data = json.load(f)
domain = 'mozilla.com'
list_name = 'genetest'
credentials = SignedJwtAssertionCredentials(
credential_data['client_email'],
credential_data['private_key'],
'https://www.googleapis.com/auth/admin.directory.group')
http_auth = credentials.authorize(Http())
# https://developers.google.com/api-client-library/python/apis/
directoryadmin = build('admin', 'directory_v1', http=http_auth)
# https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.groups.html
collection = directoryadmin.groups()
new_group = {'email': '%s@%s' % (list_name, domain),
'name': list_name}
# https://developers.google.com/resources/api-libraries/documentation/admin/directory_v1/python/latest/admin_directory_v1.groups.html#insert
request = collection.insert(body=new_group)
response = request.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment