Simple code samples to illustrate how to implement firebase functions with google spreadsheet api v4. To run this app, follow the instructions below.
Prerequisites to start this project, you need the following installed:
- A Google account
- Node.js & npm installed.
-
Clone the project. Navigate to project directory, install the packages required i.e
npm i
. -
Create Firebase account Login to an existing account or create new firebase account. After then navigate to firebase console. Create a new project and take note of the project ID and credentials.
-
Turn on the Google Sheets API Complete the steps described in Node.js Quickstart page to create a simple Node.js commmand-line application. Once google sheets API is enable, download client configuration and save/replace the file
credentials.json
to with thefirebase-function-googlesheet/functions/credentials.json
. Read more about how to generate token in Node.js Quickstart. -
Deploy Functions Once all the above, deploy the function to the firebase project you created earlier. Ensure that firebase tools is installed i.e
npm install -g firebase-tools
. You can learn more about firebase cli. Run the following commandsfirebase init
, select functionsfirebase deploy --only functions
to deploy.- Take note of the function url triggers.
There 4 basic function implemented in these project which are as follow:
-
Create new Spreadsheet
- Parameters
- spreadsheet title (title)
curl -d "title=Awesome+Spreadsheet" -X GET https://us-central1-fir-spreadsheet.cloudfunctions.net/createSpreadSheet
- Parameters
-
Create new Worksheet
- Parameters
- spreadsheet id (ssid) and
- worksheet name (title)
curl -d "ssid=1RDDg1KlVaiKA-PfHfCz_PYfV7Sj83RTxQitebvy178I&title=Sheet2" -X GET https://us-central1-fir-spreadsheet.cloudfunctions.net/createWorkSheet
- Parameters
-
Update WorkSheet
- Parameters
- spreadsheet id (ssid)
- worksheet name (sheetRange) and
- data to add/update
curl -d '{"ssid":"1RDDg1KlVaiKA-PfHfCz_PYfV7Sj83RTxQitebvy178I", "sheetRange": "Sheet2", "data":[['name', 'age', 'gender'], ['john doe', 24, 'male'], ['felicia', 28, 'female']]}' -H "Content-Type: application/json" -X POST https://us-central1-fir-spreadsheet.cloudfunctions.net/updateWorkSheet
- Parameters
-
Remove Worksheek
- Parameters
- spreadsheet id (ssid) and
- worksheet id (sheetId)
curl -d "ssid=1RDDg1KlVaiKA-PfHfCz_PYfV7Sj83RTxQitebvy178I&sheetId=492779989" -X GET https://us-central1-fir-spreadsheet.cloudfunctions.net/removeWorkSheet
- Parameters
In order for the backend service to run on Cloud Platform, you need to enable billing and APIs for the project. The Cloud Platform project is the same project you created in Create a Firebase project and has the same project identifier.
- In the Cloud Platform Console, select the Firebase project you initially created.
- Make sure that billing is enabled for your Google Cloud Platform project.