Node.js从Google电子表格中获取行返回未定义的对象

时间:2019-02-08 10:50:55

标签: node.js express

我正在尝试从Google电子表格获取值,该值将返回未定义的值。这是我的代码

app.get('\userdetails',(req,res) => {
    Var doc = new GoogleSpredsheet('sheetId');
       doc.useServiceAccountAuth(cred, function(err) {  
          doc.getRow(1, function (err, row){ console.log(row);});
    });
});

我有我的证书 作为sheetId,我已经传递了具有编辑权限的工作表ID

1 个答案:

答案 0 :(得分:1)

您需要检查,如果您在控制台日志中遇到这样的错误:

app.get('userdetails',(req,res) => {
    Var doc = new GoogleSpredsheet('sheetId');
       doc.useServiceAccountAuth(cred, function(err) {  
          if(!err){
              doc.getRow(1,function(error,row){
                  if(!error && row){
                    console.log(row);
                  }else{
                     console.log('ERROR IN getRow :'+error);
                  }
               });

          }else{
             console.log('ERROR IN useServiceAccountAuth : '+err);
          }
    });
});