Reputation: 91
I'm transitioning to the new admin-sdk api's and not finding it easy. I've figured out oath and a basic user lookup, but now I am stuck on creating a google apps account.
Here's the code I am using:
import httplib2
import pprint
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
SERVICE_ACCOUNT_EMAIL = '[email protected]'
SERVICE_ACCOUNT_PKCS12_FILE_PATH = 'privatekey.p12'
f = file(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(SERVICE_ACCOUNT_EMAIL,
key,
scope='https://www.googleapis.com/auth/admin.directory.user',
sub='[email protected]',
)
http = httplib2.Http()
http = credentials.authorize(http)
userinfo = { 'primaryEmail': '[email protected]',
'name': { 'givenName': 'Jane', 'familyName': 'Smith' },
'password': 'mypasswd',
}
service = build("admin", "directory_v1", http=http)
users = service.users()
users.insert(userinfo).execute()
And here is the result:
Traceback (most recent call last):
File "xy", line 39, in <module>
new_user = users.insert(userinfo ).execute()
TypeError: method() takes exactly 1 argument (2 given)
I have tried a lot of permutations on this theme to no avail, including:
users.insert(name='Jane Smith', password='mypasswd', name.familyName='Smith',
name.givenName='Jane', primaryEmail='[email protected]').execute()
SyntaxError: keyword can't be an expression
users.insert(name='Jane Smith', password='mypasswd', familyName='Smith',
givenName='Jane', primaryEmail='[email protected]').execute()
File "build/bdist.linux-x86_64/egg/apiclient/discovery.py", line 573, in method
TypeError: Got an unexpected keyword argument "givenName"
Any help would be greatly appreciated.
Upvotes: 3
Views: 1448
Reputation: 13528
Try:
userinfo = {'primaryEmail': '[email protected]',
'name': { 'givenName': 'Jane', 'familyName': 'Smith' },
'password': 'mypasswd',
}
service = build("admin", "directory_v1", http=http)
service.users().insert(body=userinfo).execute()
Upvotes: 6