我是管理员用户。我想与其他用户共享网站,即使是在我的域之外使用谷歌应用程序脚本。我尝试使用 ACL 并使用以下代码:
function shareSite(){
var base = 'https://sites.google.com/feeds/';
var fetchArgs = googleOAuth_('google', base);
fetchArgs.method = 'POST'
var rawXml = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:gAcl='http://schemas.google.com/acl/2007'>"
+"<category scheme='http://schemas.google.com/g/2005#kind' "
+"term='http://schemas.google.com/acl/2007#accessRule'/>"
+"<gAcl:role value='owner'/>"
+"<gAcl:scope type='user' value='newOwnerEmail'/>"
+"</entry>";
fetchArgs.payload = rawXml;
fetchArgs.contentType = 'application/atom+xml';
var url=base+'/acl/site/<domain-name>/<site-name>'
var content = UrlFetchApp.fetch(url, fetchArgs).getContentText();
Logger.log(content)
}
//Google oAuth
function googleOAuth_(name,scope) {
var oAuthConfig = UrlFetchApp.addOAuthService(name);
oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey("");
oAuthConfig.setConsumerSecret("");
return {oAuthServiceName:name, oAuthUseToken:"always",
Host: 'sites.google.com',
Authorization: 'OAuth',
oauth_version:"1.0",
oauth_nonce:"",
oauth_timestamp:"",
oauth_consumer_key:"",
oauth_token:"",
oauth_signature_method:"HMAC-SHA1",
oauth_signature:""};
}
我试过这段代码,它给出 400(错误请求),有时给出 404(未找到站点)。预期的服务器响应将是 201。如果有人知道它的解决方案和另一种方法,请与我分享。谢谢你