If you're trying to do this, you came to the right place!
Watch this code work in real time: https://twitter.com/CodingDoug/status/940022568089554944
See also this gist for copying in the other direction: https://gist.github.com/CodingDoug/44ad12f4836e79ca9fa11ba5af6955f7
-
Follow step 1 to enable Google Sheets API in your Firebase project: https://developers.google.com/sheets/api/quickstart/nodejs
-
Create a service account in your project; save the json file in the
functions
folder with the file nameserviceAccount.json
. -
Create a spreadsheet in Drive; rename the first worksheet 'Scores'; add Player and Score headers in row 1, columns A and B.
-
Share it with edit access to the email address in your service account.
-
Copy the spreadsheet id (from its URL) to the
spreadsheetId
string in the TypeScript source. -
npm install firebase-admin firebase-functions googleapis@34 lodash
-
Deploy this (TypeScript) code.
-
Update the keys/values in your database under
/scores
and watch them get updated in the sheet!
I had the same challenge...
I realized that it was caused by dependencies versions..... in package.json
I used the following versions, and it worked afterwards
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase emulators:start --only functions",
"shell": "firebase functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"engines": {
"node": "10"
},
"main": "index.js",
"dependencies": {
"firebase-admin": "^9.8.0",
"firebase-functions": "^3.14.1",
"googleapis": "^39.2.0",
"lodash": "^4.17.21"
},
"devDependencies": {
"firebase-functions-test": "^0.1.6"
},
"private": true
}