Why does SitesApp.getSites(myDomain) not work?

2019-03-06 19:33发布

问题:

I'm currently playing around with Google Apps Script and can't get the following snippet to work.

The error message is: the requested resource was not found.

I also tested the undocumented method which I found here: Need to list all the sites under a google domain using Google Apps Script

    var mySites = SitesApp.getAllSites(myDomain, 1, 10);

but I get the same error. For the complete example, see below. Thank you in advance.

function view() {
  var myDomain = 'example.com';

  // this works
  var mySite = SitesApp.getSite(myDomain);
  Logger.log('title=' + mySite.getTitle() + '\n' + 'name=' + mySite.getName());

  // this works, too
  var myPages = mySite.getAllDescendants();
  for (i in myPages) {
    Logger.log('page=' + myPages[i].getTitle());
  }  

  //this does not work, error: the requested ressource was not found
  var mySites = SitesApp.getSites(myDomain);

  // this also does not work, same error
  var mySites = SitesApp.getAllSites(myDomain, 1, 10);
}

EDIT 1: I tested with 3 different browsers on Windows 7: Firefox Nightly, Google Chrome and Opera.
EDIT 2: Same error on Samsung Galaxy Tab 10.1N with Android 3.2 and Firefox browser.

回答1:

You'll get that error when the service can't find the domain or you don't have access to it. Please ensure that the domain matches exactly, and doesn't start with "www.", etc.



回答2:

I think you should use:

  var mySite = 'https://sites.google.com/site/name_of_the_site';
  var site = SitesApp.getSiteByUrl(mySite);


回答3:

Please try the below line

for(i=0;i<=80;i++) { 

Logger.log('title=' + mySite[i].getTitle() + '\n' + 'name=' + mySite[i].getName());

 }