javascript - Google 表格 API JavaScript : Access sheet with auth

标签 javascript reactjs google-sheets-api

我可以从我的 React 应用程序中访问公共(public) Google 工作表,但现在正在尝试使用凭据访问该工作表。我找到了一个教程,可以引导我设置凭据,但该代码对我不起作用。

const {google} = require('googleapis');
const keys = require('./interstitials-key.json');

const client = new google.auth.JWT(
  keys.client_email,
  null,
  key.private_key,
  ['https://www.googleapis.com/auth/spreadsheets']
);

client.authorize(function(err, tokens){
  if(err){
    console.log(err);
    return;
  }
  else{
    console.log('connected');
  }
});

我收到此错误:

"TypeError: Expected input to be a Function or Object, got undefined"

最佳答案

这是一个已知问题,您可以在此处找到引用:

https://github.com/googleapis/google-api-nodejs-client/issues/1614

我已经重现了它,当然它没有修复,你一调用库就会遇到这个错误

const {google} = require('googleapis');

库中使用的一些资源在客户端不可用,因此无法从 React 端调用它,因此您要么在服务器端使用它,要么必须使用 google javascript 客户端API。

关于javascript - Google 表格 API JavaScript : Access sheet with auth,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58773082/

相关文章:

javascript - 为什么 Settimeout 不拉取更新后的图片 URL?

javascript - React 渲染相同的元素,它是动态组件

python - 使用 python/pandas 将数据框写入谷歌表格

ios - Google Sheets iOS - 将文档映射到 SDK

c# - 如何将模型对象或 Viewbag 传递给 Javascript?

鼠标事件的 JavaScript 函数

javascript - 服务器未发送响应

reactjs - 无法从上下文中解构对象的属性

reactjs - react : How to capture focus when a focused child component unmounts

ios - 如何使用 Sheets API v4 在 Swift 4 中创建新的 Google 表格