Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.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 谷歌电子表格;OAuth错误_Google Apps Script_Google Sheets_Oauth_Urlfetch_Google Data Api - Fatal编程技术网

Google apps script 谷歌电子表格;OAuth错误

Google apps script 谷歌电子表格;OAuth错误,google-apps-script,google-sheets,oauth,urlfetch,google-data-api,Google Apps Script,Google Sheets,Oauth,Urlfetch,Google Data Api,当我试图运行这个脚本时,我得到了一个“OAuth错误(第378行,文件“代码”)”错误 这个脚本从Google表单收集数据,运行计算(为了节省空间,我删除了计算),打开一个模板电子表格,将数据放入电子表格,并以PDF格式发送电子邮件(没有网格线) 所以我有几个问题 -我应该将我的谷歌应用登录名和密码放在oauthConfig.setConsumerKey和setConsumerCret中吗?我尝试使用“匿名”,但不断收到“执行该操作需要授权”错误 -您看到我需要更改什么来更正OAuth错误吗

当我试图运行这个脚本时,我得到了一个“OAuth错误(第378行,文件“代码”)”错误

这个脚本从Google表单收集数据,运行计算(为了节省空间,我删除了计算),打开一个模板电子表格,将数据放入电子表格,并以PDF格式发送电子邮件(没有网格线)

所以我有几个问题

-我应该将我的谷歌应用登录名和密码放在oauthConfig.setConsumerKey和setConsumerCret中吗?我尝试使用“匿名”,但不断收到“执行该操作需要授权”错误

-您看到我需要更改什么来更正OAuth错误吗

      var docTemplate = "0AgNhg8MX8TfDdHlrd3VyU0oybWhHSlBPRlU3LWlGaUE";
      var docName = "Motion Control Report";

    function formSubmitCreate(e) {
      //Variables
      //I've removed a bunch of formulas and variables, I have confirmed that all of this is correct

      //Template Info
      var copyId = DocsList.getFileById(docTemplate).makeCopy(docName+' for
'+userName+" "+userTimeStamp).getId();
      var copyDoc = SpreadsheetApp.openById(copyId);
      var copyBody = copyDoc.getActiveSheet();

      copyBody.getRange(1, 2).setValue(userName);
      //Imports a bunch of other values to the spreadsheet, removed to save space

      SpreadsheetApp.flush();

      //Save as PDF and send e-mail
      var pdf = spreadsheetToPDF(copyId);

      var subject = "Motion Control Report - " + userProjectName + " - " +userName;
      var body = userName;
      MailApp.sendEmail(userEmail, subject, body, {bcc: "matt@mocoautomation.com", htmlBody: body, attachments: pdf});

    }

    ////////////////////
    function spreadsheetToPDF(key) {

      var oauthConfig = UrlFetchApp.addOAuthService("spreadsheets");
      var scope = "https://spreadsheets.google.com/feeds"

      oauthConfig.setConsumerKey("myusername");
      oauthConfig.setConsumerSecret("password");
      oauthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
      oauthConfig.setAuthorizationUrl("https://accounts.google.com/OAuthAuthorizeToken");

      oauthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");


      var requestData = {
        "oAuthServiceName": "spreadsheets",
        "oAuthUseToken": "always",
      };
      ///GETTING OAuth ERROR FOR THIS LINE
      var pdf = UrlFetchApp.fetch("https://spreadsheets.google.com/feeds/download/spreadsheets/Export?key="+key+"&fmcmd=12&size=7&fzr=false&portrait=true&fitw=true&locale=en_GB&gid=0&gridlines=false&printtitle=false&sheetnames=false&pagenum=UNDEFINED&attachment=false",
requestData).getBlob().setName("MotionReport");

      return pdf;
    }

您不应该在代码中指定用户名和密码。要使用的密钥/秘密是
匿名
。替换为以下两行代码-

 oAuthConfig.setConsumerKey('anonymous');
 oAuthConfig.setConsumerSecret('anonymous');

您不应该在代码中指定用户名和密码。要使用的密钥/秘密是
匿名
。替换为以下两行代码-

 oAuthConfig.setConsumerKey('anonymous');
 oAuthConfig.setConsumerSecret('anonymous');

阿伦,谢谢你的帮助/我做了这些更改,现在我收到了这个错误消息“附件没有内容。(第355行,文件“代码”)”。第355行是指:;MailApp.sendEmail(用户电子邮件、主题、正文,{bcc:matt@mocoautomation.com,htmlBody:body,附件:pdf})pdf是否未正确生成或来回传递?这值得在上打开一个单独的线程,但您应该使用Logger.log函数调试代码,查看其是否为空。Arun,感谢您的帮助/我做了这些更改,现在我收到了这个错误消息“附件没有内容。(第355行,文件“代码”)”。第355行是指:;MailApp.sendEmail(用户电子邮件、主题、正文,{bcc:matt@mocoautomation.com,htmlBody:body,附件:pdf})pdf是否未正确生成或来回传递?这值得打开一个单独的线程,但您应该使用Logger.log函数调试代码,查看其是否为空。