There is an async/await function which gets data from the Google sheets. 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. I am unable to pass the values from this function to React native app. 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
. You should call the function with cl
first.async
function returns a promise. You need to await
it's resolutionapp.get("/", async function(req, res){ res.send(await gsrun(client));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.