无法使用 Google Apps 脚本更新 contactusgin People api
Cannot update contactusgin People api using Google Apps Script
我正在尝试使用 Google 应用程序 gs 中的人员服务更新现有联系人。我有这样的联系人:
let contactInfo = {
"name" : "Jhon",
"lastName": "Doe",
"phone": "+1999999",
"rn": "people/c8289118840931811524",
"etag": "%EgkBAj0JPgs/Ny4aBAECBQciDDV1TzVFdXY0ckhnPQ=="
}
为了更方便地更新联系人,我创建了以下功能:
function updateContact(contactInfo){
//var updatePersonFields = "updatePersonFields=names,phoneNumbers,emailAddresses";
var bodyRequest = {
"resourceName": contactInfo.rn,
"etag": contactInfo.etag,
"names": [{
"givenName": contactInfo.name,
"familyName": contactInfo.lastName,
}],
"phoneNumbers": [{
'value': contactInfo.phone
}],
"emailAddresses": [{
'value': contactInfo.email
}]
};
People.People.updateContact(bodyRequest, contactInfo.rn);
}
但是updateContact的文档指南需要3个参数:路径参数、查询参数和请求体:
https://developers.google.com/people/api/rest/v1/people/updateContact
为了更新联系人,我必须传递 updatePersonfields,但它是一个查询参数,而 updateContact 只接收 2 个参数。
我知道需要 etag 和 updatePersonfields,正如 link 解释的那样:
https://developers.google.com/people/v1/contacts?hl=en#update_an_existing_contact
如何添加查询参数 updatePersonFields(在评论中)?
如果 updatePersonField 没有发送,我有以下错误:
GoogleJsonResponseException: API call to people.people.updateContact failed with error:
updatePersonFields mask is required. Please specify one or more valid paths.
Valid paths are documented at
https://developers.google.com/people/api/rest/v1/people/updateContact.
先谢谢你。
根据您的情况,请将 updatePersonFields
包含到 People.People.updateContact
的第 3 个参数作为对象。
在这种情况下,当您使用 Google Apps Script 的脚本编辑器使用 Advanced Google 服务的 People API 时,您可以看到 updateContact(resource: Peopleapi_v1.Peopleapi.V1.Schema.Person, resourceName: string, optionalArgs: Object)
的文档通过脚本编辑器的自动完成。
所以,当你的脚本修改后,就变成了下面这样。
发件人:
People.People.updateContact(bodyRequest, contactInfo.rn);
收件人:
People.People.updateContact(bodyRequest, contactInfo.rn, {updatePersonFields: "emailAddresses,names,phoneNumbers"});
注:
- 当您的
bodyRequest
为无效值时,会发生错误。请注意这一点。
参考:
我正在尝试使用 Google 应用程序 gs 中的人员服务更新现有联系人。我有这样的联系人:
let contactInfo = {
"name" : "Jhon",
"lastName": "Doe",
"phone": "+1999999",
"rn": "people/c8289118840931811524",
"etag": "%EgkBAj0JPgs/Ny4aBAECBQciDDV1TzVFdXY0ckhnPQ=="
}
为了更方便地更新联系人,我创建了以下功能:
function updateContact(contactInfo){
//var updatePersonFields = "updatePersonFields=names,phoneNumbers,emailAddresses";
var bodyRequest = {
"resourceName": contactInfo.rn,
"etag": contactInfo.etag,
"names": [{
"givenName": contactInfo.name,
"familyName": contactInfo.lastName,
}],
"phoneNumbers": [{
'value': contactInfo.phone
}],
"emailAddresses": [{
'value': contactInfo.email
}]
};
People.People.updateContact(bodyRequest, contactInfo.rn);
}
但是updateContact的文档指南需要3个参数:路径参数、查询参数和请求体: https://developers.google.com/people/api/rest/v1/people/updateContact
为了更新联系人,我必须传递 updatePersonfields,但它是一个查询参数,而 updateContact 只接收 2 个参数。
我知道需要 etag 和 updatePersonfields,正如 link 解释的那样: https://developers.google.com/people/v1/contacts?hl=en#update_an_existing_contact
如何添加查询参数 updatePersonFields(在评论中)?
如果 updatePersonField 没有发送,我有以下错误:
GoogleJsonResponseException: API call to people.people.updateContact failed with error:
updatePersonFields mask is required. Please specify one or more valid paths.
Valid paths are documented at
https://developers.google.com/people/api/rest/v1/people/updateContact.
先谢谢你。
根据您的情况,请将 updatePersonFields
包含到 People.People.updateContact
的第 3 个参数作为对象。
在这种情况下,当您使用 Google Apps Script 的脚本编辑器使用 Advanced Google 服务的 People API 时,您可以看到 updateContact(resource: Peopleapi_v1.Peopleapi.V1.Schema.Person, resourceName: string, optionalArgs: Object)
的文档通过脚本编辑器的自动完成。
所以,当你的脚本修改后,就变成了下面这样。
发件人:
People.People.updateContact(bodyRequest, contactInfo.rn);
收件人:
People.People.updateContact(bodyRequest, contactInfo.rn, {updatePersonFields: "emailAddresses,names,phoneNumbers"});
注:
- 当您的
bodyRequest
为无效值时,会发生错误。请注意这一点。