简体   繁体   English

Google 表格未随 Google Places 更新 API

[英]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.我正在使用我的 API 密钥,它不会像预期的那样自动填充谷歌表格。

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.错误尝试执行 myFunction,但无法保存。
SyntaxError: Unexpected string line: 1 file: Untitled.gs SyntaxError:意外的字符串行:1 文件: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.语法错误是将用逗号分隔的字符串放在 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.请仔细阅读引用的帖子,因为它表明 function 应该用作 Google 表格公式中的自定义 function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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