Google maps 如何将谷歌云平台链接到谷歌表单脚本
如何使用API密钥或OAuth2将Google Sheet代码链接到我的付费云平台帐户。我有一个简单的应用程序脚本链接到一个简单的工作表,只要我在“免费”模式下使用它,它就可以完美地工作。但我一直无法让我的谷歌云平台帐户API与我的工作表配合使用。有人能帮我吗,或者告诉我我做错了什么 工作表的作用:从一行的前三列中选取“发件人地址”、“收件人地址”和日期时间。然后用这三个输入参数调用Google maps 如何将谷歌云平台链接到谷歌表单脚本,google-maps,google-apps-script,google-sheets,google-sheets-api,Google Maps,Google Apps Script,Google Sheets,Google Sheets Api,如何使用API密钥或OAuth2将Google Sheet代码链接到我的付费云平台帐户。我有一个简单的应用程序脚本链接到一个简单的工作表,只要我在“免费”模式下使用它,它就可以完美地工作。但我一直无法让我的谷歌云平台帐户API与我的工作表配合使用。有人能帮我吗,或者告诉我我做错了什么 工作表的作用:从一行的前三列中选取“发件人地址”、“收件人地址”和日期时间。然后用这三个输入参数调用maps.newDirectionFinder()。然后,我用距离.value、持续时间.value和持续时间
maps.newDirectionFinder()
。然后,我用距离.value
、持续时间.value
和持续时间
更新同一行中的其他三列
下面是我的代码。使用“Maps.setAuthentication(,)”
时,在调用Maps.newDirectionFinder()
的行中出现“不允许操作”错误
注意:我启用的API包括:“方向API”、“谷歌表单API”、“距离矩阵API”、“地图Javascript API”和“道路API”
代码(已删除密钥):
/********************************************************************************
*谷歌地图中的测向和路线优化例程库
*Google Maps directionFinder功能的文档如下:
* https://developers.google.com/apps-script/reference/maps/direction-finder
********************************************************************************/
//要做:
//API密钥(2018年4月11日):
/********************************************************************************
*钙距离表:
********************************************************************************/
函数calcDistanceTable(){
//var调试;
var mysheet=SpreadsheetApp.getActiveSheet();
var fromLocation=“测试字符串”;
var toLocation=“测试字符串”;
var lastRow=mysheet.getLastRow()+1;
var方向;
var stringDate=“11/03/2018 22:00”;//RR
var customDate=新日期('2018年11月2日星期四17:29:34 GMT-0700(PDT);//RR
var行=1;
//AuthenticateMaps();//RR
//下一行行不通:没有错误消息,但我的GCPAPI控制台没有显示任何请求——它似乎被忽略了
// https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&缩放=12&尺寸=400x400&按键=
//下一行失败,出现错误:TypeError:与元素类型“script”关联的属性名称“async”后面必须跟“=”字符。(第32行,文件“getDistTime”)
//
//这在我调用“directions=Maps.newDirectionFinder()”的行中失败,并显示以下错误消息:不允许操作(第50行,文件“代码”)
//设置身份验证(“,”);
做{
debug=mysheet.getRange(第1行).getValues()[0][0];
//检查第5列('E')以查看此行是否已运行此操作
if(mysheet.getRange(第5行).getValues()[0][0]您是否检查了此文档中有关的内容?
/********************************************************************************
* Library of Direction Finding and Route Optimization routines from Google Maps
* Documentation of the Google Maps directionFinder functionality is here:
* https://developers.google.com/apps-script/reference/maps/direction-finder
********************************************************************************/
// To do:
// API Key (11/04/2018): <API-key>
/********************************************************************************
* calcDistanceTable:
********************************************************************************/
function calcDistanceTable() {
// var debug;
var mysheet = SpreadsheetApp.getActiveSheet();
var fromLocation = "test string";
var toLocation = "test string";
var lastRow = mysheet.getLastRow() + 1;
var directions;
var stringDate = "11/03/2018 22:00";//RR
var customDate = new Date('Thu Nov 02 2018 17:29:34 GMT-0700 (PDT)');//RR
var row = 1;
//AuthenticateMaps();//RR
// this next line doesn't work: there is no error message, but my GCP API Console shows no requests -- it seems to be ignored
// https://maps.googleapis.com/maps/api/staticmap?center=40.714%2c%20-73.998&zoom=12&size=400x400&key=<API-key>
// this next line failed with an error: TypeError: Attribute name "async" associated with an element type "script" must be followed by the ' = ' character. (line 32, file "getDistTime")
// <script async defer src="https://maps.googleapis.com/maps/api/js?key=<API-key>&callback=initMap" type="text/javascript"></script>
// this failed on the line where I call "directions = Maps.newDirectionFinder()" with this error message: Action not allowed (line 50, file "Code")
// Maps.setAuthentication("<Client-ID>","<Secret-key>");
do {
debug = mysheet.getRange(row, 1).getValues()[0][0];
// check column 5 ('E') to see if this has been run already for this row
if(mysheet.getRange(row, 5).getValues()[0][0] <= 0){
fromLocation = mysheet.getRange(row, 1).getValues()[0][0];
toLocation = mysheet.getRange(row, 2).getValues()[0][0];
stringDate=mysheet.getRange(row, 4).getValues()[0][0];//RR
customDate=new Date(stringDate);//RR
Logger.log("row: " + row + " From: " + fromLocation + " To: " + toLocation);
directions = Maps.newDirectionFinder()
.setOrigin(fromLocation)
.setDestination(toLocation)
.setDepart(customDate)//RR
.setMode(Maps.DirectionFinder.Mode.DRIVING)
//.key=<API-key> // this didn't work: ReferenceError: "xxxxxxx" is not defined. (line xx, file "Code")
//.key="<API-key>" // this didn't work: TypeError: Cannot find function getDirections in object <API-key>
.getDirections();
mysheet.getRange(row,6).setValue(directions.routes[0].legs[0].distance.value / 1000 * 0.621371);
mysheet.getRange(row,7).setValue(directions.routes[0].legs[0].duration.value / 60);
mysheet.getRange(row,8).setValue(directions.routes[0].legs[0].duration_in_traffic.value / 60);
temp = directions; // here to set a breakpoint to pause during debug
}
row++;
} while (row < lastRow);
}