You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google People API添加联系人至分组时遇弃用组错误求助

解决Google Contacts API添加联系人到弃用分组的问题

Hey there, let's break down what's happening here and fix your issue:

错误原因解析

The error you're seeing about contactGroups/chatBuddies is because this is a deprecated system contact group in the Google Contacts API. This group was originally tied to Google Talk/Hangouts chat buddies, and Google has quietly phased out API support for modifying its members even if the deprecation isn't prominently highlighted in all docs. You won't be able to add contacts to this group via the API anymore.

解决方案与代码优化

Here's how to adjust your approach:

  1. Remove contactGroups/chatBuddies from your target groups: Since it's deprecated, you can't modify it via API. If you need a similar grouping, create a custom contact group instead.
  2. Skip contactGroups/all automatically: All new contacts are automatically added to this system group by default—you don't need to manually call the API for it.
  3. Batch process valid groups: Instead of writing repetitive code for each group, loop through your valid target groups to keep things clean.

Modified Code Example

var contactData = { 
  "phoneNumbers": [{ "type": "mobile", "value": "09876543210" }], 
  "names": [{ "unstructuredName": "Test account" }], 
  "urls": [], 
  "addresses": [{ "type": "work", "formattedValue": "0" }], 
  "organizations": [{ "name": "Organisation" }], 
  "emailAddresses": [{ "type": "home", "value": "abcd@gmail.com" }] 
};

function doGet(e) { 
  // Create the new contact
  var newContact = People.People.createContact(contactData); 
  var contactResourceName = newContact.resourceName; 

  // List of valid, modifiable target groups (excluded deprecated chatBuddies and auto-included all)
  var targetGroups = [
    "contactGroups/friends",
    "contactGroups/coworkers",
    "contactGroups/family",
    "contactGroups/blocked"
  ];

  // Loop through each group to add the contact
  targetGroups.forEach(function(groupId) {
    try {
      var group = People.ContactGroups.get(groupId);
      var membersUpdate = { "resourceNamesToAdd": [ contactResourceName ] };
      People.ContactGroups.Members.modify(membersUpdate, group.resourceName);
      console.log(`Successfully added contact to ${groupId}`);
    } catch (err) {
      console.error(`Failed to add contact to ${groupId}: ${err.message}`);
    }
  });

  return ContentService.createTextOutput(JSON.stringify({
    message: "Contact created and added to valid groups",
    contactResourceName: contactResourceName
  })); 
}

Additional Notes

  • contactGroups/blocked warning: Adding a contact to this group will block them from contacting you via Google services—double-check if this is intended for your test account!
  • Custom groups alternative: If you still need a "chat buddies"-like grouping, use People.ContactGroups.create() to make a custom group, then add contacts to it normally.

内容的提问来源于stack exchange,提问作者Code Guy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.09 08:52:42