Last active
August 1, 2018 20:01
-
-
Save aaronhoffman/afe8d6399a7c98ed25a9f466af6a9b5d to your computer and use it in GitHub Desktop.
Google Contacts API Create New Contact in My Contacts System Group. more: https://www.mycontactsync.com/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GoogleContactService | |
{ | |
public void CreateContact() | |
{ | |
var cr = this.CreateContactsRequest(); | |
var groups = cr.GetGroups().Entries.ToList(); | |
var myContactsSystemGroup = groups.FirstOrDefault(x => x.SystemGroup == "Contacts"); | |
var newContact = new Contact(); | |
// ... | |
// attempt to add to `My Contacts` system group | |
if (myContactsSystemGroup != null && !String.IsNullOrWhiteSpace(myContactsSystemGroup.Id)) | |
{ | |
newContact.GroupMembership.Add(new GroupMembership() { HRef = myContactsSystemGroup.Id }); | |
} | |
var createUri = this.CreateCreateContactUri(); | |
var createdEntry = cr.Insert(createUri, newContact); | |
} | |
private ContactsRequest CreateContactsRequest() | |
{ | |
// todo: outside the scope of this gist | |
} | |
private Uri CreateCreateContactUri() | |
{ | |
// todo: outside the scope of this gist | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blog post for context https://aaron-hoffman.blogspot.com/2018/01/create-google-contact-api-my-contacts-system-group.html