Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
从响应javascript获取JSON数据_Javascript_Json_Google Sheets Api - Fatal编程技术网

从响应javascript获取JSON数据

从响应javascript获取JSON数据,javascript,json,google-sheets-api,Javascript,Json,Google Sheets Api,我正在使用google sheets api从google电子表格中获取数据。我想使用我在控制台中获得的api数据,并在我的网站/webdashboard中使用它。我想知道如何从控制台(或任何其他数据所在的地方)获取这些数据 我在控制台中得到以下结果: Object spreadsheetId: "1dbRAXK6EVbSIFWB5mKleh2ziutwavrRLvs07uoBPJbk" valueRanges: Array(1) 0: majorDimension: "ROWS" range:

我正在使用google sheets api从google电子表格中获取数据。我想使用我在控制台中获得的api数据,并在我的网站/webdashboard中使用它。我想知道如何从控制台(或任何其他数据所在的地方)获取这些数据

我在控制台中得到以下结果:

Object
spreadsheetId: "1dbRAXK6EVbSIFWB5mKleh2ziutwavrRLvs07uoBPJbk"
valueRanges: Array(1)
0:
majorDimension: "ROWS"
range: "'ma1'!A1:J38"
values: (38) [Array(10), Array(10), Array(10), Array(9), Array(9), Array(7), Array(7), Array(9), Array(7), Array(10), Array(10), Array(9), Array(9), Array(9), Array(9), Array(8), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9)]
__proto__: Object
length: 1
__proto__: Array(0)
__proto__: Object
temp1
(38) [Array(10), Array(10), Array(10), Array(9), Array(9), Array(7), Array(7), Array(9), Array(7), Array(10), Array(10), Array(9), Array(9), Array(9), Array(9), Array(8), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9), Array(9)]
0: (10) ["maandag 1 april 2019", "", "", "", "", "", "", "", "", "week IV"]
1: (10) ["kafee", "naam", "functie", "van", "tot", "van", "tot", "Subtotaal", "totaal", "Info"]
2: (10) ["", "Ine", "", "9:30", "", "", "18:00", "8,5", "8", "Reservaties/opmerkingen"]
3: (9) ["", "Michiel", "", "9:30", "", "", "17:30", "8", "7,5"]
4: (9) ["", "Nayimi", "BT", "12:00", "", "", "21:00", "9", "8,5"]
5: (7) ["", "Gijs", "", "12:00", "", "", "18:00"]
6: (7) ["", "Flavio", "", "12:00", "", "", "21:00"]
7: (9) ["", "", "", "", "", "", "", "0", "0"]
8: (7) ["", "Tim", "V", "9:30", "", "", "18:00"]
9: (10) ["", "Griet", "V", "9:30", "", "", "18:00", "8,5", "8", "Activiteiten/voorstellingen"]
10: (10) ["", "Silvia", "V", "9:30", "", "", "18:00", "8,5", "8", "Gent Quizt"]
11: (9) ["", "Roeland", "", "17:30", "", "", "2:00", "8,5", "8"]
12: (9) ["", "Hannah", "", "17:30", "", "", "2:00", "8,5", "8"]
13: (9) ["", "Ali", "", "17:30", "", "", "2:00", "8,5", "8"]
14: (9) ["", "Emma", "", "18:00", "", "", "2:00", "8", "7,5"]
15: (8) ["", "", "", "", "", "", " ", "#VALUE!"]
16: (9) ["", "", "", "", "", "", "", "0", "0"]
17: (9) ["", "", "", "", "", "", "", "0", "0"]
18: (9) ["", "", "", "", "", "", "", "0", "0"]
19: (9) ["", "", "", "", "", "", "", "0", "0"]
20: (9) ["balzaal", "", "perm.", "", "", "", "", "0", "0"]
21: (9) ["", "", "", "", "", "", "", "0", "0"]
22: (9) ["", "", "", "", "", "", "", "0", "0"]
23: (9) ["", "", "", "", "", "", "", "0", "0"]
24: (9) ["", "", "", "", "", "", "", "0", "0"]
25: (9) ["", "", "", "", "", "", "", "0", "0"]
26: (9) ["", "", "", "", "", "", "", "0", "0"]
27: (9) ["concertzaal", "", "perm.", "", "", "", "", "0", "0"]
28: (9) ["", "", "", "", "", "", "", "0", "0"]
29: (9) ["", "", "", "", "", "", "", "0", "0"]
30: (9) ["", "", "", "", "", "", "", "0", "0"]
31: (9) ["", "", "", "", "", "", "", "0", "0"]
32: (9) ["", "", "", "", "", "", "", "0", "0"]
33: (9) ["", "", "", "", "", "", "", "0", "0"]
34: (9) ["majolica", "", "perm.", "", "", "", "", "0", "0"]
35: (9) ["", "", "", "", "", "", "", "0", "0"]
36: (9) ["", "", "", "", "", "", "", "0", "0"]
37: (9) ["", "",
我搜索了JSON GET in文件和在线api。 查看GoogleSheetsAPI文档以获得解决方案

查看了另一个堆栈溢出问题,他们将数据放在本地文件中,但这似乎是一个解决方法。我应该能够直接从api pull获取数据

<html>
  <head></head>
  <body>
    <!--
    BEFORE RUNNING:
    ---------------
    1. If not already done, enable the Google Sheets API
       and check the quota for your project at
       https://console.developers.google.com/apis/api/sheets
    2. Get access keys for your application. See
       https://developers.google.com/api-client-library/javascript/start/start-js#get-access-keys-for-your-application
    3. For additional information on authentication, see
       https://developers.google.com/sheets/api/quickstart/js#step_2_set_up_the_sample
    -->
    <script>
    function makeApiCall() {
      var params = {
        // The ID of the spreadsheet to retrieve data from.
        spreadsheetId: 'my-spreadsheet-id',  // TODO: Update placeholder value.

        // The A1 notation of the values to retrieve.
        range: 'my-range',  // TODO: Update placeholder value.

        // How values should be represented in the output.
        // The default render option is ValueRenderOption.FORMATTED_VALUE.
        valueRenderOption: '',  // TODO: Update placeholder value.

        // How dates, times, and durations should be represented in the output.
        // This is ignored if value_render_option is
        // FORMATTED_VALUE.
        // The default dateTime render option is [DateTimeRenderOption.SERIAL_NUMBER].
        dateTimeRenderOption: '',  // TODO: Update placeholder value.
      };

      var request = gapi.client.sheets.spreadsheets.values.get(params);
      request.then(function(response) {
        // TODO: Change code below to process the `response` object:
        console.log(response.result);
      }, function(reason) {
        console.error('error: ' + reason.result.error.message);
      });
    }

    function initClient() {
      var API_KEY = '';  // TODO: Update placeholder with desired API key.

      var CLIENT_ID = '';  // TODO: Update placeholder with desired client ID.

      // TODO: Authorize using one of the following scopes:
      //   'https://www.googleapis.com/auth/drive'
      //   'https://www.googleapis.com/auth/drive.file'
      //   'https://www.googleapis.com/auth/drive.readonly'
      //   'https://www.googleapis.com/auth/spreadsheets'
      //   'https://www.googleapis.com/auth/spreadsheets.readonly'
      var SCOPE = '';

      gapi.client.init({
        'apiKey': API_KEY,
        'clientId': CLIENT_ID,
        'scope': SCOPE,
        'discoveryDocs': ['https://sheets.googleapis.com/$discovery/rest?version=v4'],
      }).then(function() {
        gapi.auth2.getAuthInstance().isSignedIn.listen(updateSignInStatus);
        updateSignInStatus(gapi.auth2.getAuthInstance().isSignedIn.get());
      });
    }

    function handleClientLoad() {
      gapi.load('client:auth2', initClient);
    }

    function updateSignInStatus(isSignedIn) {
      if (isSignedIn) {
        makeApiCall();
      }
    }

    function handleSignInClick(event) {
      gapi.auth2.getAuthInstance().signIn();
    }

    function handleSignOutClick(event) {
      gapi.auth2.getAuthInstance().signOut();
    }
    </script>
    <script async defer src="https://apis.google.com/js/api.js"
      onload="this.onload=function(){};handleClientLoad()"
      onreadystatechange="if (this.readyState === 'complete') this.onload()">
    </script>
    <button id="signin-button" onclick="handleSignInClick()">Sign in</button>
    <button id="signout-button" onclick="handleSignOutClick()">Sign out</button>
  </body>
</html>

由于我找不到任何关于如何工作或如何搜索的信息,我无法给出如何实现这一点的示例。

结果的数据位于
response.result.values
中,这是一个数组数组。要获取单元格
B1
的值,请使用
response.result.values[1][0]
(A=0,B=1,C=2,…;从数值单元格索引中减去1,因为数组中的第一个元素是索引0)

您到底在问什么……如何将该数据转换为html表?确实我知道我有这些数据,但无法像我想要的那样使用它们。我很高兴我在正确的对象上得到了它-(response.result)。谢谢!对不起,我误解了。看看我的新答案。这正是我需要的。我是根据你的第一个答案得出结果的。再次感谢。
      var request = gapi.client.sheets.spreadsheets.values.get(params);
      request.then(function(response) {
        // TODO: Change code below to process the `response` object:
        console.log(response.result);
      }, function(reason) {
        console.error('error: ' + reason.result.error.message);
      });