我可以从我的 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 aFunction
orObject
, gotundefined
"
最佳答案
这是一个已知问题,您可以在此处找到引用:
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/