Create / Update / Delete Contact in Gmail using VB.NET

1,167 views
Skip to first unread message

Kathan shah

unread,
Aug 31, 2012, 3:26:05 PM8/31/12
to google-co...@googlegroups.com
i want to Create / Update / Delete Contact in Gmail using VB.NET application

please help me with example

foram

unread,
Sep 7, 2012, 4:57:35 PM9/7/12
to google-co...@googlegroups.com
I am working in asp.net C# below is code

pass user name and password in request settings.for shared contact pass admin user name and password.

retrieve contacts
 RequestSettings rs = new RequestSettings("test", Session["username"].ToString(), Session["pass"].ToString());
        ContactsRequest cr = new ContactsRequest(rs);       
        ContactsQuery query = new ContactsQuery(uri.ToString());
        Feed<Contact> f = cr.Get<Contact>(query);  

Insert contacts

 Contact newEntry = new Contact();
  
  newEntry.Name = new Name()
      {
        FullName = "Elizabeth Bennet",
        GivenName = "Elizabeth",
        FamilyName = "Bennet",
      };
  newEntry.Content = "Notes";
  // Set the contact's e-mail addresses.
  newEntry.Emails.Add(new EMail()
      {
        Primary = true,
        Rel = ContactsRelationships.IsHome,
        Address = "l...@gmail.com"
      });
  newEntry.Emails.Add(new EMail()
      {
        Rel = ContactsRelationships.IsWork,
        Address = "l...@example.com"
      });
  // Set the contact's phone numbers.
  newEntry.Phonenumbers.Add(new PhoneNumber()
      {
        Primary = true,
        Rel = ContactsRelationships.IsWork,
        Value = "(206)555-1212",
      });
  newEntry.Phonenumbers.Add(new PhoneNumber()
      {
        Rel = ContactsRelationships.IsHome,
        Value = "(206)555-1213",
      });
  
  // Set the contact's postal address.
  newEntry.PostalAddresses.Add(new StructuredPostalAddress()
      {
        Rel = ContactsRelationships.IsWork,
        Primary = true,
        Street = "1600 Amphitheatre Pkwy",
        City ="Mountain View",
        Region = "CA",
        Postcode = "94043",
        Country = "United States",
        FormattedAddress = "1600 Amphitheatre Pkwy Mountain View",
      });
  // Insert the contact.
  Uri feedUri = new Uri(ContactsQuery.CreateContactsUri("default"));
  Contact createdEntry = cr.Insert(feedUri, newEntry);


Update Contact

 Contact contact = cr.Retrieve<Contact>(contactURL);
        contact.Name.FullName = "New Name";
        contact.Name.GivenName = "New";
        contact.Name.FamilyName = "Name";
        try
        {
            Contact updatedContact = cr.Update(contact);
        }
        catch (GDataVersionConflictException e)
        {
            // Etags mismatch: handle the exception.
        }

Delete contact

 Contact contact = cr.Retrieve<Contact>(contactURL);

        try
        {
            cr.Delete(contact);
        }
        catch (GDataVersionConflictException e)
        {
            // Etags mismatch: handle the exception.
        }


for shared contact pass domain name in uri instead of default.

Hope this works
Reply all
Reply to author
Forward
0 new messages