I have tested and made it successful on getting Google spreadsheet using cloud functions in FlutterFlow.
The code below get an ID as the input from FlutterFlow app and returns the title of the Googe spreadsheet document.
It may update this code to return whole data or part of the data. You may also update this method to pass line no. cell. no for CRUD (Create, Read, Update, Delete).
Get service account
Share the google spreadsheet document with the service account
Set the service account email and private key in the code
Then, deploy
js code
/* eslint-disable max-len */
const {onCall} = require("firebase-functions/v2/https");
const {GoogleSpreadsheet} = require("google-spreadsheet");
const {JWT} = require("google-auth-library");
exports.getSpreadsheetTitle = onCall(
{cors: [/\.app$/, /\.com$/]},
async (request) => {
const serviceAccountAuth = new JWT({
email: "withce....eaccount.com",
key: "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggS....4HVgWP7G+WtUWtyU\noIZ9mJwA6WTVfRlbZViB/II=\n-----END PRIVATE KEY-----\n",
scopes: [
"https://www.googleapis.com/auth/spreadsheets",
],
});
const doc = new GoogleSpreadsheet(request.data && request.data.id ? request.data.id : "16LGEgT2...dFL4z-8pGWu0mE", serviceAccountAuth);
await doc.loadInfo();
return {
id: request.data.id,
title: doc.title,
};
},
);
```
```json
{
"name": "functions",
"description": "Firebase Custom Cloud Functions",
"engines": {
"node": "18"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^12.0.0",
"firebase-functions": "^4.9.0",
"google-spreadsheet": "^4.1.1"
},
"private": true
}