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個代碼,但沒有更新。 –