WELCOME

This blog is where I post about my consulting work with Microsoft Technologies, and other random tidbits that don't fit in my Photo Blog or my Iraq Blog.

Tuesday, February 2, 2010

Souce code for deleting Google/Gmail Contact Groups

Over a year ago I posted a little utility for deleting unwanted groups out of your Gmail Contacts.

Blog post here: http://blog.scrappydog.com/2009/01/deleting-4000-gmail-groups-or-repairing.html

Application install here: http://scrappydog.com/GoogleGroupCleanup/publish.htm

I wrote this for my own use because a bad replication tool had created 10,000+ bogus groups in my Contacts, and I REALLY didn't want to delete them by hand!

Apparently, it has saved a fair number of other people's bacon as well...

Today "Ben" asked if I could post the source code for my tool? And so here it is (not much to it):


using System;
using Google.GData.Contacts;

namespace GoogleGroupCleanup
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine("Google Gmail Group Cleanup Tool");
Console.WriteLine();
Console.WriteLine("Written by: Eric Bowen (googlegroupcleanup@scrappydog.com)");
Console.WriteLine();
Console.WriteLine("This application is provided WITHOUT any guarantee. Use at your own risk.");
Console.WriteLine();
Console.WriteLine("This application will delete ALL groups from your Gmail account.");
Console.WriteLine("It will NOT delete any of your contacts or email.");
Console.WriteLine();
Console.WriteLine(
"This application deletes up to 1,000 groups at a time. If you have more than 1,000 groups to delete you will need to run it multiple times.");


Console.WriteLine();
Console.Write("Enter Google email address (this will not be stored): ");
string email = Console.ReadLine();

Console.WriteLine();
Console.Write("Enter Google password (this will not be stored): ");
string password = Console.ReadLine();

var service = new ContactsService("gmail-group-cleanup");
service.setUserCredentials(email, password);

var groupQuery = new GroupsQuery(GroupsQuery.CreateGroupsUri("default"));
groupQuery.NumberToRetrieve = 1000;
var groupsFeed = service.Query(groupQuery);

int counter = 0;
foreach (GroupEntry group in groupsFeed.Entries)
{
Console.WriteLine(group.Content.Content);
group.Delete();
counter++;
}

Console.WriteLine();
Console.WriteLine(counter.ToString() + " groups deleted");
Console.WriteLine();
}
catch (Exception ex)
{
Console.WriteLine("Exception:");
Console.WriteLine(ex.Message);
Console.WriteLine();
}
Console.WriteLine("Press any key to exit");
Console.ReadKey();
}
}
}

8 comments:

John said...

Thank you, thank you, thank you! After hours of trying to delete all of the groups (483) created on my gmail account, your program took care of it in about 2 minutes, so thank you more than I could ever say!!!

Tom Terrific said...

Thanks - I don't know why Google doesn't build in this basic tool. You saved me a lot of aggravation and time.

Jennifer said...

OMG you are such a time saver. I have been trying to figure out how to get all those groups out for a month now. I have been slowly deleting them when I have time. You are my favorite person today!

kpdriscoll said...

Great tool! Why does Google allow duplicate group name in the first place? My burn came from the Thunderbird Google Contacts sync.

kpdriscoll said...

Great tool! Why does Google allow duplicate group name in the first place? My burn came from the Thunderbird Google Contacts sync.

A.R. Mann said...

I'm not sure if I did something wrong...At the end it said it deleted 1000 groups. However, I still have numerous groups with the same name (and with only one contact in each).

Any thoughts?

A.R. Mann said...

After using the tool, it said it deleted 1000 groups. However, when I went back into Gmail to look at my contacts there were loads of identical group names with 1 contact.

Any thoughts?

Thanks,

Roberto said...

ANOTHER grateful user. Thank you SOOO much!!