简体   繁体   中英

Google Sheets not updating with Google Places API

I'm using the code from the answer provided . I'm using my API key and it will not populate the google sheets automatically like it's suppose to.

function placesAPI("Golf Course","51.4977836","-0.1522502","20000","AIzaSyAojD0lY2mwzWgKhB8FLZnn7FiAXTgGuj4",20) {
  var output = [ ["Name", "Place ID", "Latitude", "Longitude", "Types"]]
  var url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?types=food&location=51.4977836,-0.1522502&radius=200&key=AIzaSyAojD0lY2mwzWgKhB8FLZnn7FiAXTgGuj4";
  var response = UrlFetchApp.fetch(url)
  payload = JSON.parse(response);
  for (var x = 0; x < payload['results'].length; x++){
    var inner = [payload['results'][x]['name'], payload['results'][x]['place'],payload['results'][x]['latitude'],payload['results'][x]['longitude'],payload['results'][x]['types']]
    output.push(inner)}
  return(output); // added this code to put the value on the cell
}

Error Attempted to execute myFunction, but could not save.
SyntaxError: Unexpected string line: 1 file: Untitled.gs

I've tried opening up a new sheet, running my code in a new file under "Script" but the same error.

The syntax error is putting strings separated by commas inside the parenthesis of placesAPI.

Please read carefully the referred post as it shows that the function should is intended to be used as custom function in a Google Sheets formula.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM