0
我无法通过Python中的Google Directory API修补/更新我的用户的自定义字段。我正在使用google-api-python-client/1.5.1。通过Python中的Google Directory API为用户修补/更新自定义字段
我可以使用由脚本生成的json通过https://developers.google.com/admin-sdk/directory/v1/reference/users/patch修补/更新自定义字段。我也可以用我的脚本生成的json使用curl进行修补。但是,当我尝试直接从我的脚本进行修补/更新时,不会做任何更改。奇怪的是,我成功地用同样的语法修补其他字段(手机号码,固定电话等)。
...
OAUTH_SCOPE = 'https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.group'
credentials = SignedJwtAssertionCredentials(
'service-account-email',
key,
scope=OAUTH_SCOPE,
sub='[email protected]')
httplib2.debuglevel = 1
http = httplib2.Http()
http = credentials.authorize(http)
directory_service = build('admin', 'directory_v1', http=http)
params = {'customer': 'my_customer'}
...
Get user info from LDAP, returns mail, mobile and groups
...
patch = {'phones':
[
{'value': mobile, 'type': 'work_mobile', 'primary': 'true'}
]
}
try:
patchr = directory_service.users().patch(userKey=mail, body=patch).execute(http=http)
except errors.HttpError as e:
print e
customSchemas['aswSchema']['adGroups'] = []
for group in groups:
customSchemas['aswSchema']['adGroups'].append({'value': group})
patchg = json.dumps(customSchemas)
try:
patchr = directory_service.users().patch(userKey=mail, body=patchg).execute(http=http)
except errors.HttpError as e:
print e
....
patchg变量,例如以下:
{"aswSchema":
{"adGroups":
[
{"value": "r_app_app1-ro"},
]
}
}
我看到这个使用httplib2的调试日志:
send: 'PATCH /admin/directory/v1/users/user%40example.net?alt=json HTTP/1.1\r\nHost: www.googleapis.com\r\ncontent-length: 69\r\naccept-encoding: gzip, deflate\r\naccept: application/json\r\nuser-agent: google-api-python-client/1.5.1 (gzip)\r\ncontent-type: application/json\r\nauthorization: Bearer very-long-string\r\n\r\n"{\\"aswSchema\\": {\\"adGroups\\": [{\\"value\\": \\"r_net_app1-ro\\"}]}}"'
reply: 'HTTP/1.1 200 OK\r\n'
但用户不会更新与广告组的字段。
可能是什么问题?
不幸的是,没有为我工作。此外,我不再能够通过API Explorer自由格式编辑器进行更新,我必须使用结构化编辑器 - 否则我会收到200个代码,但没有更新。 –