Search code examples
gdata-apigoogle-sitesgoogle-data-apigdata-java-client

How to Delete a Google Site by its id


I am unable to find out how can I delete a Google Site given its ID. I guess I need to create the SiteEntry for that site and call delete() method, but no idea on how to create the SiteEntry with just the ID.

This is how I am creating the sites:

SitesService client = new SitesService("domain-AppName-v1");
client.setUserCredentials("[email protected]", "password");

//Define Site
SiteEntry entry = new SiteEntry();
entry.setTitle(new PlainTextConstruct("Accounting 001"));
entry.setSummary(new PlainTextConstruct("Accounting 001"));

entry.getCategories().add(new Category(TagCategory.Scheme.TAG, "Course Sessions", null));

//Create the site
SiteEntry result = client.insert(new URL("https://sites.google.com/feeds/site/domain.com/"), entry);

//This Delete does not work
result.delete();

//Trying to setup the id in a SiteEntry, it doesn't work either
SiteEntry e = new SiteEntry();
e.setId(result.getId());
e.delete();

Solution

  • This turned out to be a stupid question.

    First, https://developers.google.com/google-apps/sites/faq#DeleteSite states the API doesn't support deleting Sites yet, and they must be deleted manually via the web panel. This really sucks because I currently have hundreds of sites created with the API and it is a pain in the ass to delete them manually :-(

    Second, siteEntry.delete() throws an Exception saying "delete not implemented", so I was wrong when adding that as working in the question code.

    Finally, to retrieve a SiteEntry you must do like this:

    SitesService client = <initialize the service>
    SiteEntry site = client.getEntry(new URL(siteID), SiteEntry.class);