Dau*_*udi 2 python google-directory-api
我正在尝试迁移到 google admin sdk。我正在尝试使用 python 将成员添加到组(邮件列表)。我已经弄清楚如何创建组,但无法弄清楚如何添加成员。我已阅读此页面:https : //developers.google.com/admin-sdk/directory/v1/reference/members/insert但无法弄清楚如何将其映射到 python(我对 REST 或 python 几乎没有经验,我我正在努力学习)。
这就是我尝试这样做的方式:
import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
keyFile = file(p12File, 'rb')
key = keyFile.read()
keyFile.close()
credentials = SignedJwtAssertionCredentials(serviceAccount,
key,
scope,
prn=superAdmin)
http = httplib2.Http()
httplib2.debuglevel = False #change this to True if you want to see the output
http = credentials.authorize(http=http)
directoryService = build(serviceName='admin', version='directory_v1', http=http)
# THIS DOES NOT WORK
groupinfo = {'email': 'wibble@XXX.co.uk'}
directoryService.groups().insert(groupKey='mygroup@XXX.co.uk', body=groupinfo).execute()
Run Code Online (Sandbox Code Playgroud)
当我运行时,我得到:
Traceback (most recent call last):
File "add-member-to-group.py", line 58, in <module>
directoryService.groups().insert(groupKey='mygroup@XXX.co.uk', body=groupinfo).execute()
File "/usr/local/lib/python2.7/dist-packages/googleapiclient/discovery.py", line 604, in method
raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "groupKey"
Run Code Online (Sandbox Code Playgroud)
如果有人能帮助我弄清楚如何做到这一点,我将不胜感激。
在进一步寻找之后,我解决了它。最后一行应该是:
directoryService.members().insert(groupKey='mygroup@XXX.co.uk', body=groupinfo).execute()
Run Code Online (Sandbox Code Playgroud)
即目录服务。成员()... 不是 directoryService。组()...
这里的例子帮助我解决了这个问题。