How to access Cloud Firestore from Google Sheets?

Tushar Rai

I am trying to access Cloud Firestore database from Google sheet with the help of FirestoreGoogleAppsScript example, but as explained in the 5th point I have downloaded the file but not getting where to update the client_email, private_key and project_id in the project. So kindly guide me to move forward.

When you press "Create," your browser will download a .json file with your private key (private_key), service account email (client_email), and project ID (project_id). Copy these values into your Google Apps Script — you'll need them to authenticate with Firestore.

with a demo Code.gs

function myFunction() {
  projectid: "xxx";
  key: "-----BEGIN PRIVATE KEY-----\nPrivateKeyHere\n-----END PRIVATE KEY-----\n";
  email: "[email protected]";
  
  var firestore = FirestoreApp.getFirestore(email, key, projectId);
}

error

ReferenceError: "email" is not defined. (line 7, file "Code")
Renaud Tarnec

You have to do as follows, for example in a simple function that fetches a collection:

function fecthFirstCollectionDocs() {

  var email = "[email protected]";
  var key = "-----BEGIN PRIVATE KEY-----\your key here\n-----END PRIVATE KEY-----\n";
  var projectId = "zzzzzzzzz";

  var firestore = FirestoreApp.getFirestore(email, key, projectId);

  const allDocuments = firestore.query("FirstCollection").execute();
  Logger.log(JSON.parse(allDocuments));

}

The value of key is obtained by creating a service account, as explained in the Library documentation: https://github.com/grahamearley/FirestoreGoogleAppsScript#creating-a-service-account. It's quite easy, just follow the instructions.

You have to copy only the part between -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY-----\n from the .json file.


Edited following you comment of 9 April:

To solve the

ReferenceError: "email" is not defined. (line 7, file "Code") 

error you should correctly declare the variables you pass to the getFirestore() method, as shown in the code of my answer, and as follows:

instead of doing

  projectid: "fir-79c39";

you should do

  var projectid = "fir-79c39";

You declare a variable named projectid that you use in the getFirestore() method. The same for key and email.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

How to access Cloud Firestore from Google Sheets?

分類Dev

How to access Google Cloud Platform Firestore triggers from Python runtime cloud functions

分類Dev

Uploading and downloading files to/from Google Cloud Firestore

分類Dev

How to access google sheets without authentication?

分類Dev

How can I upload files to Cloud Storage through Cloud Functions and use Firestore to control access to Cloud Storage?

分類Dev

How to use variables in dot notation in Google Cloud Firestore

分類Dev

How to fetch or get data from Cloud Firestore Firebase in android

分類Dev

How to retrieve a list of custom objects from Cloud Firestore in Android

分類Dev

How to filter date from meta property with ImportXML in Google Sheets

分類Dev

How to Import All Element Nodes in Google Sheets from XML

分類Dev

How to delete all unprotected rows in a range of particular sheets from Google Sheets using Apps Scripts

分類Dev

Google Cloud - How to grant access to group of secrets by label or name?

分類Dev

Google cloud storage Aws migration, how to get access/secret key?

分類Dev

Google Cloud dataproc not able to access hive metastore from cloudsql with --scopes=cloud-platform

分類Dev

Google BigQuery, How to load data from google cloud storage to BigQuery

分類Dev

Google Cloud FTP and SSH Access

分類Dev

How to Fix Google Sheets RTL?

分類Dev

Firebase Cloud Firestore - Accessing a collection from a reference

分類Dev

Deleting document from cloud_firestore in flutter

分類Dev

Find and replace data from columns - Google Sheets

分類Dev

Google DataflowからGoogle Cloud Firestoreへの出力

分類Dev

Unable to access AWS s3 bucket from Private Google cloud composer

分類Dev

Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

分類Dev

Cloud Firestore: how to reference another document?

分類Dev

How can i import JSON into Cloud Firestore

分類Dev

Cannot access MySQL database on Google Cloud

分類Dev

Flutter and Firestore: How can access variables from Stateful Widget to create a new document?

分類Dev

How do you access a Google Sheet with a service account from Java?

分類Dev

How do I grant public access to my file stored in google cloud storage

Related 関連記事

  1. 1

    How to access Cloud Firestore from Google Sheets?

  2. 2

    How to access Google Cloud Platform Firestore triggers from Python runtime cloud functions

  3. 3

    Uploading and downloading files to/from Google Cloud Firestore

  4. 4

    How to access google sheets without authentication?

  5. 5

    How can I upload files to Cloud Storage through Cloud Functions and use Firestore to control access to Cloud Storage?

  6. 6

    How to use variables in dot notation in Google Cloud Firestore

  7. 7

    How to fetch or get data from Cloud Firestore Firebase in android

  8. 8

    How to retrieve a list of custom objects from Cloud Firestore in Android

  9. 9

    How to filter date from meta property with ImportXML in Google Sheets

  10. 10

    How to Import All Element Nodes in Google Sheets from XML

  11. 11

    How to delete all unprotected rows in a range of particular sheets from Google Sheets using Apps Scripts

  12. 12

    Google Cloud - How to grant access to group of secrets by label or name?

  13. 13

    Google cloud storage Aws migration, how to get access/secret key?

  14. 14

    Google Cloud dataproc not able to access hive metastore from cloudsql with --scopes=cloud-platform

  15. 15

    Google BigQuery, How to load data from google cloud storage to BigQuery

  16. 16

    Google Cloud FTP and SSH Access

  17. 17

    How to Fix Google Sheets RTL?

  18. 18

    Firebase Cloud Firestore - Accessing a collection from a reference

  19. 19

    Deleting document from cloud_firestore in flutter

  20. 20

    Find and replace data from columns - Google Sheets

  21. 21

    Google DataflowからGoogle Cloud Firestoreへの出力

  22. 22

    Unable to access AWS s3 bucket from Private Google cloud composer

  23. 23

    Google Sheets: How do I create an array from a range, adding a column with a constant literal value in every row?

  24. 24

    Cloud Firestore: how to reference another document?

  25. 25

    How can i import JSON into Cloud Firestore

  26. 26

    Cannot access MySQL database on Google Cloud

  27. 27

    Flutter and Firestore: How can access variables from Stateful Widget to create a new document?

  28. 28

    How do you access a Google Sheet with a service account from Java?

  29. 29

    How do I grant public access to my file stored in google cloud storage

ホットタグ

アーカイブ