谷歌应用脚​​本日历授权需要循环 [英] google apps script calendar authorization required loop

查看:9
本文介绍了谷歌应用脚​​本日历授权需要循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个存储表单数据的电子表格.一旦在表单提交上提交数据,我就会运行一个脚本,该脚本使用谷歌地图进行一些距离计算,并将相关信息通过电子邮件发送给相关利益相关者.

i have a spreadsheet which stores data from a form. once data is submitted on form submit i have a script running that does some distance calculations using google maps and emails relevant information to the relevant stakeholders.

脚本还会在电子表格中具有特定数据的列上运行,然后再次将相关信息通过电子邮件发送给相关利益相关者,并应该在默认日历中创建一个事件.

script is also run upon a column in the spreadsheet having certain data which then again emails the relevant information to the relevant stakeholders and is supposed to create an event in the default calendar.

脚本一直运行良好,但自从我插入 calendarapp.getdefaultcalendar 开始创建事件后,我不断获得授权所需屏幕提示我该脚本将管理我的日历、查看和管理我的电子表格、以我的身份发送电子邮件并连接到外部服务.这一切都很好,我接受了提示,只是它不断地反复出现.

script has been working fine but ever since i have inserted the calendarapp.getdefaultcalendar to start creating events i keep getting the authorization required screen prompting me that the script would to manage my calendars, view and manage my spreadsheets, send email as me and connect to external services. this is all fine and i accept the prompt except it keeps coming back up over and over again.

任何建议请帮助.我是否达到了某种配额,它是什么?

any suggestions please help. have i reached a some type of quota, what is it?

function myFunction() {

  var DISTANCE_COLUMN = 14;
  var DURATION_COLUMN = 15;
  var COST_COLUMN = 16;
  var ROUTE_COLUMN = 17;
  var STATE_COLUMN = 18;
  var BOOKED_COLUMN = 19;

  var EMAILED_STATE = "EMAILED";
  var BOOKED_STATE = "BOOKED";

  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0]; // gets sheet 0 from active spreadsheet

  var data = getRowsData(sheet); // gets all the data from the active spreadsheet using 
                                 // the getRowsData function below 

  for (var i = 0; i < data.length; i++) { // for every row within the active spreadsheet
  var row = data[i];

  row.rowNumber = i + 2;

if(!row.distance) { // check to see if distance already exists
  var mapsURL = 'http://maps.google.com/maps/api/directions/xml?origin=' + row.pickUpAddress + ' Victoria&destination=' + row.dropOffAddress + ' Victoria&sensor=false&units=metric&mode=driving';
  var mapsXML = UrlFetchApp.fetch(mapsURL).getContentText();
  var mapsResponse = Xml.parse(mapsXML, true);
  var distance = mapsResponse.DirectionsResponse.route.leg.distance.getElement("value").getText();
  var duration = mapsResponse.DirectionsResponse.route.leg.duration.getElement("value").getText();

  var distance = Math.round(distance / 1000); // convert distance in to kilometers
  var duration = Math.round(duration / 60); //convert duration in to minutes
  var cost = 0;


  // Changes the date fields in to strings so that we can compare for tarif one. 
  var formattedPickUpTime = Utilities.formatDate(row.pickUpTime, "GMT+1000", "HHmmss");
  var formattedFromTime = Utilities.formatDate(new Date("12/30/1899 23:00:00"), "GMT+1100", "HHmmss");
  var formattedToTime = Utilities.formatDate(new Date("12/31/1899 04:00:00"), "GMT+1100", "HHmmss");


  var mapsRoute = '"http://maps.google.com/maps?f=d&source=s_d&saddr=' + row.pickUpAddress + ' Victoria&daddr=' + row.dropOffAddress + ' Victoria&mode=driving"';

  sheet.getRange(row.rowNumber, DISTANCE_COLUMN).setValue(distance); // set distance value
  sheet.getRange(row.rowNumber, DURATION_COLUMN).setValue(duration); // set duration value
  sheet.getRange(row.rowNumber, COST_COLUMN).setValue(cost); // set cost value
  sheet.getRange(row.rowNumber, ROUTE_COLUMN).setValue(mapsRoute); // set map of route value
}

if(!row.state) { // check to see if emails have already been sent
  stakeholderEmailFYI(row, distance, duration, cost, mapsRoute); // send an FYI email to the stakeholder
  // customerEmailConfirmation(row); // send a confirmation email to the customer
  sheet.getRange(row.rowNumber, STATE_COLUMN).setValue(EMAILED_STATE); // change state value to SENT      
}

if(row.sendBooking == "Y") { // check to see if emails have already been sent
  // customerEmailConfirmation(row); // send a confirmation email to the customer

  var eventStartTime = row.pickUpTime;
  // End time is calculated by adding an hour in the event start time
  var eventEndTime = new Date(row.pickUpTime.valueOf()+60*60*1000);

  var cal = CalendarApp.getDefaultCalendar().createEvent(row.fullName, eventStartTime, eventEndTime, {location: row.pickUpAddress});

  // cal.createEvent(row.fullName, eventStartTime, eventEndTime, {location: row.pickUpAddress});
  sheet.getRange(row.rowNumber, BOOKED_COLUMN).setValue(BOOKED_STATE); // change state value to SENT
}
}
}

推荐答案

尝试撤销授权,重新授权脚本,有时可以解决问题.

Try to revoke authorizations and re-authorize the script, sometimes it solves the problem.

这样做:2 种可能性:

To do so : 2 possibilities :

  1. 您已收到一封邮件,告知您已授权此应用,该邮件包含一个自动卸载功能的链接(但这是由其他人或您的另一个帐户编写的应用
  2. 您知道脚本的名称,但您没有那么多脚本,请转到您的 Google 个人资料/安全/撤销访问权限,有一个您授权的所有脚本的列表以及每个脚本的卸载按钮.
  3. (是的,我知道我说过 2 :) 使用脚本的 url,如下所示:

  1. You have received a mail telling you you authorized this app, this mail has a link to an automatic uninstall feature (but this is when the app is written by someone else or another of your accounts
  2. You know the name of the script and you don't have so much scripts, go to your Google profile/security/revoke access , there is a list of all the scripts you authorized and a button for each of them to uninstall.
  3. (Yes I know I said 2 :) use the url of your script which is something like below :

https://script.google.com/macros/d/MZMgUL88c4hd6qj_G2Y7-rKtIT_UhbT9n/edit?uiv=2&tz=Europe/Brussels&docTitle =测试+ STO&安培; CSID = tAeLIRLHehPkQGfa6zUYzpg.11577354092571548890.6605670643166911759&安培;中= ACjPJvG-INu6kmfFfm649tuH-6KYNVpaz5G9uEy4CUMmcKAVn7RYVi8euALNy9dfPWl6gkCloq5D6SKrqczHteazKR2F41v5K5bqbw&安培; HL = EN_US

删除/edit?..."之后的所有内容,包括/edit?"

remove everything after "/edit?..." including "/edit?"

并添加 /manage/uninstall

让它变成这样:

https://script.google.com/macros/d/MZMgUL88c4h_G2Y7-rKtIT_UhbT9n/管理/卸载

这将带您进入类似这样的页面:

This will bring you to a page like this one :

点击卸载,你就完成了……处女还是处女……

Click uninstall and your done... virgin as a virgin...

然后重新授权,看看情况是否好转.

Then re-authorize to see if things go better.

这篇关于谷歌应用脚​​本日历授权需要循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆