Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script 如何在Google apps脚本中将使用ACL的站点共享给其他用户?_Google Apps Script_Google Apps - Fatal编程技术网

Google apps script 如何在Google apps脚本中将使用ACL的站点共享给其他用户?

Google apps script 如何在Google apps脚本中将使用ACL的站点共享给其他用户?,google-apps-script,google-apps,Google Apps Script,Google Apps,我是一个管理员用户。我想与其他用户共享网站,即使是在我的域名之外,也可以使用谷歌应用程序脚本。我已尝试使用ACL并使用了以下代码: function shareSite(){ var base = 'https://sites.google.com/feeds/'; var fetchArgs = googleOAuth_('google', base); fetchArgs.method = 'POST' var rawXml = "<entry xmlns='htt

我是一个管理员用户。我想与其他用户共享网站,即使是在我的域名之外,也可以使用谷歌应用程序脚本。我已尝试使用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:""};
}
函数共享站点(){
var base=https://sites.google.com/feeds/';
var fetchArgs=googleOAuth(“google”,base);
fetchArgs.method='POST'
var rawXml=“”
+""
+""
+""
+"";
fetchArgs.payload=rawXml;
fetchArgs.contentType='application/atom+xml';
var url=base+'/acl/site/'
var content=UrlFetchApp.fetch(url,fetchArgs.getContentText();
Logger.log(内容)
}
//谷歌oAuth
googleOAuth函数(名称、范围){
var oAuthConfig=UrlFetchApp.addOAuthService(名称);
oAuthConfig.setRequestTokenUrl(“https://www.google.com/accounts/OAuthGetRequestToken?scope=“+范围);
oAuthConfig.setAuthorizationUrl(“https://www.google.com/accounts/OAuthAuthorizeToken");
oAuthConfig.setAccessTokenUrl(“https://www.google.com/accounts/OAuthGetAccessToken");
oAuthConfig.setConsumerKey(“”);
oAuthConfig.setConsumerCret(“”);
返回{oAuthServiceName:name,oAuthUseToken:“始终”,
主持人:“sites.google.com”,
授权:“OAuth”,
oauth_版本:“1.0”,
oauth_nonce:“”,
oauth_时间戳:“”,
oauth_消费者_密钥:“”,
oauth_令牌:“”,
oauth_签名_方法:“HMAC-SHA1”,
oauth_签名:“};
}
我试过这段代码,它给出400(错误的请求),有时给出404(未找到站点)。 预期的服务器响应为201。 如果有人知道它的解决方案和其他方法,那么请与我分享。
谢谢

我建议使用内置的SitesApp服务修改ACL
Site.addCollaborator()
应该执行您想要的操作