Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script Google Places-脚本-开放时间功能不起作用_Google Apps Script_Google Places Api - Fatal编程技术网

Google apps script Google Places-脚本-开放时间功能不起作用

Google apps script Google Places-脚本-开放时间功能不起作用,google-apps-script,google-places-api,Google Apps Script,Google Places Api,我正在使用一个基于GooglePlacesAPI的脚本来获取一个地方在Google上显示的开放时间 这是我的密码: function hor(place, city, state) { var API_KEY = 'xxx'; var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' + place + ' ' + city + ' ' + state + '&am

我正在使用一个基于GooglePlacesAPI的脚本来获取一个地方在Google上显示的开放时间

这是我的密码:

      function hor(place, city, state) {
      var API_KEY = 'xxx';
      var url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' +
      place + ' ' + city + ' ' + state + '&key=' + API_KEY;
      var response = UrlFetchApp.fetch(url);
      var json = response.getContentText();
      obj = JSON.parse(json);
      hours = obj.results[0].opening_hours;
      return hours;
当我运行ggsheet函数“horaires”时,出现以下错误:

TypeError:无法从“未定义”中读取属性“营业时间”

你知道是什么导致了这个错误吗

非常感谢你的帮助, 提姆


文档:

根据文档,返回的对象有一个名为
result
的键,不是复数形式,当您试图在代码中访问时,它也是一个对象而不是数组

电话应该是

hours = obj.result.opening_hours;
请注意,要获得单独的小时数,您必须更加具体<代码>营业时间是一个带有字段的对象。要获得一周第一天的开放时间,你必须

hours = obj.result.opening_hours.periods[0].open.time

这将返回商店周日开门的时间。

您在哪里使用“开门时间”属性?抱歉,我的版本错误。我刚刚编辑了ITI,不幸的是,我遇到了同样的问题“TypeError:无法从未定义的文件中读取属性“opening_hours”。(第84行)。“您确定URL是正确的吗?”?如果您记录响应,您会得到什么?