Set Maps API key in Script Editor

后端 未结 4 1883
醉酒成梦
醉酒成梦 2020-12-18 05:52

As far as I understand, in order to track our quota usage, we need to provide our API key to the Google App Service on the service we are planning to use.

In my case

4条回答
  •  北荒
    北荒 (楼主)
    2020-12-18 06:24

    1.) I added an API key from my console dashboard. Remember to select the correct project you are working on. https://console.developers.google.com/apis/credentials?project=

    2.) In my Project (Scripts Editor) I setAuthentication to Maps using the API key and the Client ID from the console. I have included the script below:

    function getDrivingDirections(startLoc, wayPoint, endLoc){
       var key = "Your_API_Key";
       var clientID = "Your_Client_ID";
       Maps.setAuthentication(clientID, key);
       var directions =  Maps.newDirectionFinder()
            .setOrigin(startLoc)
            .addWaypoint(wayPoint)
            .setDestination(endLoc)
            .setMode(Maps.DirectionFinder.Mode.DRIVING)
            .getDirections();
    } return directions;
    

    https://developers.google.com/apps-script/reference/maps/maps#setAuthentication(String,String)

提交回复
热议问题