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 应用程序脚本上的设置共享方法不适用于G套件用户?_Google Apps Script - Fatal编程技术网

Google apps script 应用程序脚本上的设置共享方法不适用于G套件用户?

Google apps script 应用程序脚本上的设置共享方法不适用于G套件用户?,google-apps-script,Google Apps Script,我正在尝试创建文档并设置其访问权限。 下面的代码适用于我的普通Gmail帐户 但是,当我在唯一的GSuite地址上运行它时,它会返回以下错误: TypeError:在对象文档中找不到函数SetShareing。(行 6、文件“代码”) 代码如下: function createAndSendDocument() { //Create a new Google Doc named 'Hello, world!' var doc = DocumentApp.create('Hell

我正在尝试创建文档并设置其访问权限。 下面的代码适用于我的普通Gmail帐户

但是,当我在唯一的GSuite地址上运行它时,它会返回以下错误:

TypeError:在对象文档中找不到函数SetShareing。(行 6、文件“代码”)

代码如下:

    function createAndSendDocument() {

  //Create a new Google Doc named 'Hello, world!'
  var doc = DocumentApp.create('Hello World');

  //Set user permissions to view and edit.
  doc.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.EDIT);

  //Access the body of the document, then add a Paragraph.
  doc.getBody().appendParagraph('This is a test document for people to see and try and lorem ipsum.');

  //Get the URL of the doc
  var url = doc.getUrl();

  //Get email address of the active user - aka you.
  var email = 'example@domain.com';

  //Get the name of doc to use as an email subject line
  var subject = doc.getName();

  //Add a new strong to the url variable to use as an email body.
  var body = 'Link to your document: ' + url;

  //Send yourself an email with a link to the document.
  GmailApp.sendEmail(email, subject, body); 

}

如何解决此问题或正确使用setSharing方法?我是否使用了错误的方法,或者我是否遗漏了其他步骤,因为我从非GSuite帐户中遇到了此问题,并通过使用驱动器api而不是文档api解决了此问题

e、 g


工作正常,但当我使用
DocumentApp.getFileById
时,它没有工作。我自己也遇到了类似的问题,可能会对您有所帮助。我使用DocumentApp api创建了一个文档。然后我使用DriveApp api设置共享。请注意,从同一文档中获得的URL是不同的。如果您将从DocumentApp获得的文档URL通过电子邮件发送给您的G套件组织外部的人,他们将必须登录才能打开文档,即使共享设置为“任何具有链接的人。无需登录”。但是如果您将从DriveApp获得的URL通过电子邮件发送给您的G套件组织外部的人,他们将能够轻松打开链接,无需登录。因此,我认为如果您使用DriveApp设置您创建的文档的共享,您的代码可能会工作得更好。然后确保通过电子邮件发送从DriveApp api获得的URL,而不是从DocumentApp api获得的URL

function myFunction() {
var doc = DocumentApp.create("Test Document");
Logger.log("This is the URL that I get with DocumentApp: " + doc.getUrl());

var documentFileID = doc.getId();
var myFileDriveApp = DriveApp.getFileById(documentFileID);
Logger.log("This is the drive app URL: " + myFileDriveApp.getUrl());

//Set the sharing on the file using DriveApp
myFileDriveApp.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);

}

你是说这里的电子邮件吗example@domain.com'; ?
function myFunction() {
var doc = DocumentApp.create("Test Document");
Logger.log("This is the URL that I get with DocumentApp: " + doc.getUrl());

var documentFileID = doc.getId();
var myFileDriveApp = DriveApp.getFileById(documentFileID);
Logger.log("This is the drive app URL: " + myFileDriveApp.getUrl());

//Set the sharing on the file using DriveApp
myFileDriveApp.setSharing(DriveApp.Access.ANYONE_WITH_LINK, DriveApp.Permission.VIEW);