Reputation: 11
I was getting a list of contacts using the Contact method in Google App Script. As of June 16th, the Contact method is not longer available. I am trying to use the People method but cannot figure out how to get a specific list of email addresses categorized by the label. Please help and TYIA
Original Google App Script:
var emailList = [];
var contacts = ContactsApp.getContactGroup('Membership Committee').getContacts();
for(var i in contacts){
emailList.push(contacts[i].getEmailAddresses());
}
Upvotes: 0
Views: 725
Reputation: 5533
As answered by Rafa Guillermo:
contactGroups.get
to get the group member resource names.people.getBatchGet
to make a batch request to the API and use member resource names and personFields: 'emailAddresses'
as parameters.Example:
function myFunction() {
var groupId = "Insert Group/Label ID here"
var contactGroup = People.ContactGroups.get('contactGroups/'+groupId, {"maxMembers" : 50});
var memberResourceNames = contactGroup.memberResourceNames;
var test = People.People.getBatchGet({
resourceNames: memberResourceNames,
personFields: 'emailAddresses'
})
test.responses.forEach(res => {
Logger.log(res.person.emailAddresses[0].value);
})
}
Note: Label ID can be found by clicking a Label and in the URL, any characters after https://contacts.google.com/label/
is the ID.
Output:
Upvotes: 0