gpt4 book ai didi

用于配置用户 google apps admin-sdk 的 python 代码

转载 作者:太空宇宙 更新时间:2023-11-03 13:45:18 25 4
gpt4 key购买 nike

我正在过渡到新的 admin-sdk api,但并不容易。我已经想出了誓言和基本的用户查找,但现在我坚持创建一个谷歌应用程序帐户。

这是我使用的代码:

import httplib2
import pprint
import sys

from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials

SERVICE_ACCOUNT_EMAIL = 'xyz@developer.gserviceaccount.com'
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='myadmin@mydomain.edu',
)
http = httplib2.Http()
http = credentials.authorize(http)

userinfo = { 'primaryEmail': 'jane@mydomain.edu',
'name': { 'givenName': 'Jane', 'familyName': 'Smith' },
'password': 'mypasswd',
}

service = build("admin", "directory_v1", http=http)
users = service.users()
users.insert(userinfo).execute()

结果如下:

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)

我在这个主题上尝试了很多排列都无济于事,包括:

users.insert(name='Jane Smith', password='mypasswd', name.familyName='Smith', 
name.givenName='Jane', primaryEmail='jane@testg.berkeley.edu').execute()

SyntaxError: keyword can't be an expression

users.insert(name='Jane Smith', password='mypasswd', familyName='Smith',
givenName='Jane', primaryEmail='jane@testg.berkeley.edu').execute()

File "build/bdist.linux-x86_64/egg/apiclient/discovery.py", line 573, in method
TypeError: Got an unexpected keyword argument "givenName"

如有任何帮助,我们将不胜感激。

最佳答案

尝试:

userinfo = {'primaryEmail': 'jane@mydomain.edu',
'name': { 'givenName': 'Jane', 'familyName': 'Smith' },
'password': 'mypasswd',
}
service = build("admin", "directory_v1", http=http)
service.users().insert(body=userinfo).execute()

关于用于配置用户 google apps admin-sdk 的 python 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21641045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com