Skip to content

Instantly share code, notes, and snippets.

@haqiramadhani
Last active February 17, 2022 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haqiramadhani/effb21021bc68278b71a87c8b30d936f to your computer and use it in GitHub Desktop.
Save haqiramadhani/effb21021bc68278b71a87c8b30d936f to your computer and use it in GitHub Desktop.
Membuat contact di google dengan google app script, sync ke android.
function test() {
createContact('Test Contact', '08273488734', '');
}
function doGet( req ) {
const { action, ...data } = req.parameter;
switch(action) {
case "create":
const { name, phone, email } = data;
createContact( name, phone, email );
return response().json({
sucess: true,
message: 'Berhasil menyimpan kontak ke Google Contacts'
});
break;
default:
break;
}
}
function createContact(name, phone, email) {
const contact = ContactsApp.createContact(name, '', '');
contact.setMobilePhone(phone);
if (email) contact.setPrimaryEmail(email);
const group = ContactsApp.getContactGroup('System Group: My Contacts');
group.addContact(contact);
return contact;
}
function response() {
return {
json: function(data) {
return ContentService
.createTextOutput(JSON.stringify(data))
.setMimeType(ContentService.MimeType.JSON);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment