Firebase托管提供错误错误:无法处理请求

时间:2018-06-14 05:40:52

标签: node.js firebase

我使用 firebase hosting 来获取使用node js API的Google电子表格数据。如果我获取1000行,但是当我获取10000时它会很好,它会给我错误错误:无法处理请求

以下是1000请求的网址 https://us-central1-valuemyplace-1525346661329.cloudfunctions.net/app/spreadsheet

以下是10000请求的网址 https://us-central1-valuemyplace-1525346661329.cloudfunctions.net/app/test

这是我的代码

function listMajors(auth) {
  const sheets = google.sheets({version: 'v4', auth});
  sheets.spreadsheets.values.get({
    spreadsheetId: '1Lpbx-LQQTh-lF2E1lQmPnqZhvT2bWfQ9gxBX-qGBz_M',
    range: 'A1:P120933',
    //valueRenderOption: 'UNFORMATTED_VALUES'
    //majorDimension: 'COLUMNS'
  }, (err, {data}) => {
    if (err) return console.log('The API returned an error: ' + err);
    const rows = data.values;
    if (rows.length) {
      rows.map((row) => {
        const zipObj = (arr1, arr2, obj) => {
          if (arr1.length === 0 || arr2.length === 0) { return 0; }
          obj[arr1[0]] = arr2[0];
          return zipObj(arr1.slice(1), arr2.slice(1), obj);
        }

        const ress = [];

        for (let i = 1; i < rows.length; i++) {
          let obj = {};
          zipObj(data.values[0], data.values[i], obj);
          ress.push(obj);
        }

        //console.log(res);
        firebase.database().ref().set(ress);
        res.send(ress);
       // console.log(row.length);
      });
    } else {
      console.log('No data found.');
    }
  });
}

请帮我解决这个问题。提前谢谢。

1 个答案:

答案 0 :(得分:1)

我自己使用

解决了
function listMajors(auth) {
  const sheets = google.sheets({version: 'v4', auth});
  sheets.spreadsheets.values.get({
    spreadsheetId: '1Lpbx-LQQTh-lF2E1lQmPnqZhvT2bWfQ9gxBX-qGBz_M',
    range: 'A1:P120933',
    //valueRenderOption: 'UNFORMATTED_VALUES'
    //majorDimension: 'COLUMNS'
  }, (err, {data}) => {
    if (err) return console.log('The API returned an error: ' + err);
    const rows = data.values;
    if (rows.length) {
      ** //rows.map((row) => {** *Do comment here*
        const zipObj = (arr1, arr2, obj) => {
          if (arr1.length === 0 || arr2.length === 0) { return 0; }
          obj[arr1[0]] = arr2[0];
          return zipObj(arr1.slice(1), arr2.slice(1), obj);
        }

        const ress = [];

        for (let i = 1; i < rows.length; i++) {
          let obj = {};
          zipObj(data.values[0], data.values[i], obj);
          ress.push(obj);
        }

        //console.log(res);
        firebase.database().ref().set(ress);
        res.send(ress);
       // console.log(row.length);
      **//});** *Comment Here*
    } else {
      console.log('No data found.');
    }
  });
}