仅删除 Google 个联系人中的 "System Group: My Contacts" 个联系人
Delete contacts only in "System Group: My Contacts" in Google Contacts
下面的代码删除了 Goggle Contacts 中 ID 与 Google Sheets 上的 ID 不匹配的所有联系人。但问题是它会删除所有不匹配的联系人。但是,我只想从系统组:我的联系人中删除联系人。
代码:
function deleteSingleContacts() {
Utilities.sleep(3000);
var contactIds = ContactsApp.getContacts().map(function(contact) {
return contact.getId(); // Get current contact ids
});
var sh3 = SpreadsheetApp.getActive().getSheetByName("MacRadio's Customers"); // Please change accordingly
var currentIds = sh3.getRange("R5:R").getValues().map(function(value) {
return value[0];
}).filter(function(val) {
return val != "";
})
for (var i = 0; i < contactIds.length; i++) {
if (currentIds.indexOf(contactIds[i]) == -1) {
var contact = ContactsApp.getContactById(contactIds[i]);
ContactsApp.deleteContact(contact);
}
}
}
将 ContactsApp.getContacts()
替换为 ContactsApp.getContactsByGroup(group)
和 var group = ContactsApp.getContactGroup('My Contacts');
。
下面的代码删除了 Goggle Contacts 中 ID 与 Google Sheets 上的 ID 不匹配的所有联系人。但问题是它会删除所有不匹配的联系人。但是,我只想从系统组:我的联系人中删除联系人。
代码:
function deleteSingleContacts() {
Utilities.sleep(3000);
var contactIds = ContactsApp.getContacts().map(function(contact) {
return contact.getId(); // Get current contact ids
});
var sh3 = SpreadsheetApp.getActive().getSheetByName("MacRadio's Customers"); // Please change accordingly
var currentIds = sh3.getRange("R5:R").getValues().map(function(value) {
return value[0];
}).filter(function(val) {
return val != "";
})
for (var i = 0; i < contactIds.length; i++) {
if (currentIds.indexOf(contactIds[i]) == -1) {
var contact = ContactsApp.getContactById(contactIds[i]);
ContactsApp.deleteContact(contact);
}
}
}
将 ContactsApp.getContacts()
替换为 ContactsApp.getContactsByGroup(group)
和 var group = ContactsApp.getContactGroup('My Contacts');
。