如何将我的密钥添加到此Google应用程序脚本? [英] How to add my key to this google app script?

查看:120
本文介绍了如何将我的密钥添加到此Google应用程序脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要更新此脚本以传递我的密钥,这样我才不会超过每天的限制.我将如何修改此脚本以传递我的密钥?

I need to update this script to pass my key so that I don't go over the limit per day. How would I modify this script to pass my key?

(注意:可在此处找到google类信息: https://开发人员. google.com/apps-script/reference/maps/geocoder )

(NOTE: google class information found here: https://developers.google.com/apps-script/reference/maps/geocoder)

    function geo2zip(a) {
      var response=Maps.newGeocoder()
        .reverseGeocode(lat(a),long(a));
      return response.results[0].formatted_address.split(',')[2].trim().split(' ')[1];
    }
    function lat(pointa) {
     var response = Maps.newGeocoder()
         .geocode(pointa);
      return response.results[0].geometry.location.lat
    }
    function long(pointa) {
      var response = Maps.newGeocoder()
         .geocode(pointa);
      return response.results[0].geometry.location.lng
    }

我以前从未使用过Google Apps脚本.

I have never used a google apps script before.

我已经安装了该脚本,并且正在使用"= geo2zip(cell)"从我的Google工作表中调用该脚本以获取不完整地址的邮政编码.我的床单上有〜28k.我已在Google控制台和帐单信息中启用了地理编码API.并创建了我的密钥,但不确定如何在上面的脚本中包含我的密钥.

I have this script in place and am using "=geo2zip(cell)" to call the script from my google sheet to get the zip code for incomplete addresses. There are ~28k in my sheet. I have enabled the geocoding api in my google console and my billing info. and created my key but am not sure how to include my key in the script above.

我也尝试过使用以下命令通过我的密钥来调用api.它正在工作,但这导致响应速度非常慢.按照这些回复的速度,我将需要10天才能完成更新我的28k记录.

I have also tried using the following to call the api using my key. It is working, but this has resulted in VERY slow responses. At the rate it is taking these to respond, it will take me 10 days to finish updating my 28k records.

CELL M4852->" https://maps.googleapis.com/maps/api/geocode/xml?address=ADDRESS&key=MYKEY " 下一个单元格->"== ImportXML(M4852,"/GeocodeResponse/result/formatted_address)"

CELL M4852--> "https://maps.googleapis.com/maps/api/geocode/xml?address=ADDRESS&key=MYKEY" NEXT CELL--> "=ImportXML(M4852,"/GeocodeResponse/result/formatted_address")"

该脚本的响应速度更快,因此我更愿意使用该脚本并传递我的密钥.请让我知道是否可以帮忙.

The script responds much more quickly, so I would prefer to use that and pass my key. Please let me know if you can help.

更新:我能够使用下面的Alberto建议添加Maps.setAuthentication来解决此问题.

UPDATE: I was able to resolve this using Alberto's suggestion below of adding the Maps.setAuthentication.

推荐答案

我相信您的问题更多与Google API管理有关,而不是与脚本本身有关.有一种方法可以限制您的密钥使用量.根据Maps Platform文档:

I believe your issue has more to do with the Google API management than with the scripts themselves. There is a way to limit how much your key is used. According to the Maps Platform documentation:

管理使用成本

Manage Your Cost of Use

管理您使用Google地图的费用 平台API,您可以为任何请求的所有请求设置每日限制 可计费的API.

To manage your cost of use of the Google Maps Platform APIs, you can set daily limits to all requests to any billable API.

要查看或更改Geocoding API的每日可计费限制,请执行 以下:

To view or change daily billable limits for the Geocoding API, do the following:

转到Google Cloud Platform中的地址解析API配额页面 安慰.从项目列表中,选择一个项目.在要求中 部分,在每日请求"行上,点击修改图标,然后输入 首选的可计费每日总配额,最高限额(如果有) 由Google指定.

Go to the Geocoding API Quotas page in the Google Cloud Platform Console. From the projects list, select a project. In the Requests section, on the Requests per day line, click the edit icon, then enter the preferred total billable daily quota, up to the limit (if any) specified by Google.

您基本上可以设置每天要允许多少个请求,这样可以避免超出限制.

You can basically set how many requests you want to allow per day, which will avoid you going over your limit.

更新

根据文档,您可以使用Maps.setAuthentication(clientId, signingKey)方法将该脚本链接到您的帐户:

You can link the script to your account using the Maps.setAuthentication(clientId, signingKey) method, according to the docs, it:

允许使用外部建立的Maps API for Business 帐户,以利用额外的配额配额.您的客户编号和 签名密钥可以从Google Enterprise支持门户获取. 将这些值设置为null可返回使用默认配额 津贴.

Enables the use of an externally established Maps API for Business account, to leverage additional quota allowances. Your client ID and signing key can be obtained from the Google Enterprise Support Portal. Set these values to null to go back to using the default quota allowances.

地图文档链接: https://developers.google.com/apps-script/reference/maps/maps#setAuthentication(String,String)

配额URL: https://console.cloud.google.com/project/_/apiui/apiview/geocoding_backend/quotas?_ga=2.141719605.643331044.1560431279-1498828710.1560431279

文档URL: https://developers.google.com/地图/文档/地理编码/使用和计费

这篇关于如何将我的密钥添加到此Google应用程序脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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