我正在嘗試將腳本從Profiles API遷移到Directory API。其目的是使用includeInGlobalAddressList屬性來管理某些Google Apps域用戶的聯繫信息的可見性。無法使用目錄API更改includeInGlobalAddressList
我可以獲取用戶對象,並且能夠提交修補程序請求,但不會進行更改。從patch方法返回的對象具有includeInGlobalAddressList的原始值。在api文檔中有一些對etags的模糊引用,但是我不清楚etag是否應該包含在patch主體中或作爲If-Match頭文件。 (?如果這個問題的答案是如果-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。
我不認爲你應該在將patch體傳遞給patch()方法之前將其轉換爲字符串。 – 2014-10-13 20:46:29