google-apps-scriptgoogle-workspacegoogle-sitesgoogle-sites-2016google-site-verification-api

Retrieve all classic and new google sites using google sites api


Is there a way to retrieve all the new google sites, including the classic sites? I tried using getAllSites(domain, start, max).

// This writes the a list of sites in domain yourdomain.com to the log.
function getNumberOfSites() {
  var pageStart = 0;
  var pageSize = 50;
  while (true) {
    Logger.log("Loading sites starting at %s", pageStart, pageSize);
    var sites = SitesApp.getAllSites("yourdomain.com", pageStart, pageSize);
    // Logger.log(sites);
    if (sites.length == 0) {
      break;
    }
    Logger.log("Got %s sites back", sites.length);
    pageStart += sites.length;
    for(var i in sites) {
      Logger.log("Found site: %s", sites[i].getUrl());
    }
  }
  
}

But I could only retrieve the classic sites which has a prefix /a/ (eg: https://sites.google.com/a/yourdomain.com/demo/). Is there a way I can retrieve both classic and new google sites (which doesn't have a prefix /a/ eg: https://sites.google.com/yourdomain.com/demo/)?


Solution

  • Site Service can only access Classic Google Sites as stated in the official document.

    A rebuilt version of Sites was launched on November 22, 2016. Apps Script cannot currently access or modify Sites made with this version, but script can still access classic Sites.


    Based on this reference: When will available the API Google Site?

    The new version of Google Sites does not offer an API at the moment but Google has announced that API capabilities including Google Apps Script integration will be available.

    For more detailed information see Deprecation Timeline - classic Google Sites

    Google doesn't offer dates for when features will be available so you won't find one.