[英]How to pass value getting from Google sheets to Node JS to show into React Native as a Flatlist
There is an async/await function which gets data from the Google sheets.有一个 async/await function 从 Google 表格中获取数据。 I have used a return statement for a single cell value in the end of the function and when I pass this into node JS then it throws an error that argument must be of type string or array not a function.
我在 function 的末尾对单个单元格值使用了 return 语句,当我将它传递给节点 JS 时,它会抛出一个错误,即参数必须是字符串或数组类型,而不是 function。 I am unable to pass the values from this function to React native app.
我无法将此 function 中的值传递给 React 本机应用程序。 Below is the sample code
下面是示例代码
async function gsrun(cl){
const gsapi = google.sheets({version : "v4", auth: cl});
const opt = {
spreadsheetId : '<spreadsheet id>',
range: 'Range to get values'
}
var data = await gsapi.spreadsheets.values.get(opt);
var dataArray = data.data.values;
return dataArray[2][1]
}
var a = gsrun(client)
app.get("/", function(req, res){
res.send(a);
})
res.send
.res.send
。 You should call the function with cl
first.cl
调用 function。async
function returns a promise. async
function返回 promise。 You need to await
it's resolutionawait
它的解决方案app.get("/", async function(req, res){ res.send(await gsrun(client));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.