Skip to content

Instantly share code, notes, and snippets.

@aaronhoffman
Last active August 1, 2018 20:01
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 aaronhoffman/afe8d6399a7c98ed25a9f466af6a9b5d to your computer and use it in GitHub Desktop.
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/
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
}
}
@aaronhoffman
Copy link
Author

note: this uses the Google GData Contacts nuget package: https://www.nuget.org/packages/Google.GData.Contacts

@aaronhoffman
Copy link
Author

@aaronhoffman
Copy link
Author

aaronhoffman commented Jun 1, 2018

Project site that uses this to sync contacts between gmail accounts: https://www.mycontactsync.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment