Deleting contact photos using .NET


If you want to delete a contact photo from the Contacts API using the .NET client library, you can just call ContactsService.Delete(photoURI), like so:

ContactsService service = new ContactsService("exampleCo-exampleApp-1");
service.setUserCredentials("user@example.com", "secretPassword");
ContactsQuery query = new ContactsQuery(ContactsQuery.CreateContactsUri("default"));

ContactsFeed feed = service.Query(query);
foreach (ContactEntry entry in feed.Entries)
{
  service.Delete(entry.PhotoEditUri);
}

Be careful, the above code will delete every contact photo in your contact list. Run this against a test account only.

3 comments:

SathishKumar said...

Hey,
After performing the delete operation,the contact Photos doesnt get deleted in my account.I am newbie.Kindly guide me.

Trevor Johns said...

@SathishKumar: Can you post this to the Contacts API help group? The people there should be able to help diagnose what the problem is.

http://groups.google.com/group/google-contacts-api

Mary Petter said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.