I have a time-triggered script that periodically retrieves content from an external source and updates a Google sites page with it. According to this, the script should be running under my account, which has full assess to that Google site page (tested by manually editing it). But when I run the script, I get the
You do not have permission to perform that action.
Why do I not have that permission when running the script, if I can edit the page manually?
Here is the (generalized) script function:
function updatePage() {
var site = 'https://sites.google.com/a/mydomain.com/myhome/mypagegroup/mypage';
var pageName = '/mypagegroup/mypage';
var site = SitesApp.getSiteByUrl(site);
var page = site.getChildByName(pageName); //works fine
Logger.log('page: ' + page.getTitle()); //displays correct page title
var html = '<p>'; //in actual script, I get html from external source
Logger.log('html: ' + html);
page.setHtmlContent(html); //this is where the error is generated ("You do not have permission to perform that action")
};
In the script editor, did you choose the function name from the drop down list, and click the run icon?
The first time you run it this way, a pop up will display, stating that authorization is needed. You must give authorization to modify sites. If that hasn't been done, you'll get an error.
Authorize sites:
I ran your code, after authorizing the script, and it worked.
You can go into your account, and check what projects you have given permissions to. You need to choose "Account", and then click "Get Started" in the Security checkup section of the Account settings window.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With