1

我正在尝试将脚本从 Profiles API 迁移到 Directory API。其目的是使用 includeInGlobalAddressList 属性管理某些 Google Apps 域用户的联系信息的可见性。

我可以获取用户对象,并能够提交补丁请求,但没有进行更改。从 patch 方法返回的对象具有 includeInGlobalAddressList 的原始值。api 文档中有一些对 etag 的模糊引用,但我不清楚 etag 是否应该包含在补丁正文中或作为 If-Match 标头。(如果答案是 If-Match 标头,那么我应该如何使用 python 库传递它?)

http = httplib2.Http()
http = credentials.authorize(http)

service = build("admin", "directory_v1", http=http)
usersvc=service.users()
d=usersvc.get(userKey=userkey, projection="basic",fields="etag,id,includeInGlobalAddressList").execute()
visible = d['includeInGlobalAddressList']
# logic to decide what change elided. this is "transition from visible to invisible contact"
pch=json.dumps({'includeInGlobalAddressList': False, 'etag': d['etag']})
print pch
res=usersvc.patch(userKey=userkey, body=pch, fields="etag,id,includeInGlobalAddressList").execute()
print json.dumps(res, indent=4)

我得到的结果是:

{"includeInGlobalAddressList": false, "etag": "\"WIg4sZOp0a-9Z5MJXVMQx1SQW5A/avXX6NaPX78Y6qFG7S4TqKFMIEU\""}
{
    "includeInGlobalAddressList": true, 
    "etag": "\"WIg4sZOp0a-9Z5MJXVMQx1SQW5A/J0MuBtIvJoTcifknCMScMlyCQnc\"", 
    "id": "109793672165131484748"
}

即使我不使用fields或不通过 etag,也会发生这种情况。

4

1 回答 1

0

在 PATCH 请求之前无需执行 GET。PATCH 的想法是只通过线路发送更改的数据。尝试:

service = build("admin", "directory_v1", http=http)
usersvc = service.users()
res = usersvc.patch(userKey=userkey, body={"includeInGlobalAddressList": False}, fields="id,includeInGlobalAddressList").execute()
print res
于 2014-10-08T16:53:06.947 回答