google-apps-script - 更新 Google 域共享联系人照片
问题描述
我正在使用 Google Apps 脚本访问域共享联系人并使用 People API 更新联系人信息。
我可以使用以下方法成功地将联系人照片添加到授权用户联系人:
var photoClass = {photoBytes: Utilities.base64EncodeWebSafe(testIDPhotoBlob.getBytes()),
personFields:'photos'};
var testId = 'people/c12345678901234'
var updatePhoto = People.People.updateContactPhoto(photoClass,testId);
这成功地更新了联系人照片。请注意,联系人是用户联系人,并且是带有“people/c”的存在。
如果我使用相同的方法更新域共享联系人:
var photoClass = {photoBytes: Utilities.base64EncodeWebSafe(testIDPhotoBlob.getBytes()),
personFields:'photos'};
var testId = 'people/d12345678901234'
var updatePhoto = People.People.updateContactPhoto(photoClass,testId);
请注意,联系人 ID 以“person/d”开头。这将返回错误:
GoogleJsonResponseException: API call to people.people.updateContactPhoto failed with error: Resource name "people/d12345678901234" is not a valid contact person resource.
域联系人确实存在为:
var testPersonSearch = People.People.searchDirectoryPeople({query:'Domain Contact Name',readMask:findFields,sources:['DIRECTORY_SOURCE_TYPE_DOMAIN_CONTACT']});
Returns:
{ people:
[ { organizations: [Object],
names: [Object],
phoneNumbers: [Object],
emailAddresses: [Object],
etag: '%xxxxxx/yyyyyyy',
resourceName: 'people/d12345678901234"' } ],
totalSize: 1 }
我了解旧 API /m8/feeds 没有正确实现此功能。
如果我对 SharedContactsAPI 使用以下代码:
var contact = SharedContactsApp.getContactById('hexadecimalValueofContact');
console.log(contact.hasProfilePicture());
returns false as contact is valid but no image exists....
console.log(contact.setProfilePicture(testIDPhotoBlob));
returns null
此外,通过直接使用 UrlFetchApp.fetch 等使用 REST API 会得到类似的结果,说明无法找到联系人。
解决方案
对于共享联系人,您需要使用共享联系人 API
头脑:
共享联系人 API 仅适用于外部联系人。使用此 API 为域用户或组创建联系信息可能会导致这些用户和组的联系信息重复,这可能会导致意外行为。
要实现Shared Contacts API
with Apps 脚本,您可以使用开源SharedContactsApp库。该文档为您提供了如何使用它的说明和示例。
推荐阅读
- mysql - 如何正确组合这些 SELECTS (MySQL)?
- floating-point - 是否有任何二进制值没有精确的十进制表示?
- python - 删除索引列
- python - xarray 中的 Combine_by_Coords 给出 numpy 警告
- php - 选择数据库记录到表格中
- asp.net - 如何检查gridview是否被篡改
- visual-studio - VS 2019 项目不断神奇地恢复到 .Net Core 3.0
- php - 如何在查询中使用 groupby 以避免冗余行
- javascript - 未捕获的类型错误:无法读取 HTMLAnchorElement.linkAction 处未定义的属性“添加”
- java - 繁荣菜单崩溃