13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

firestoreにgoogle app script

Last updated at Posted at 2017-11-19

課題

  • アプリのバックエンドにfirebase ( auth / firestore / cloud function ) を使用している
  • その時のマスタデータの扱いにスプレッドシートを使いたい

作戦

  • spread sheet => gas => firestore

APEENDIX

やったこと

GASへライブラリの読み込み

メニューからリソース => ライブラリ => MX2_NUfxVpaA1XPcZ_N-3wWb_Hp7BVbw3 を入力
保存

サービスアカウントの作成

下記のページにアクセスし新規アカウントを作成
https://console.developers.google.com/projectselector/iam-admin/serviceaccounts
※ cloud databaseのowner(書き込み、読み込み)のアクセス権にする
※ json形式で鍵を保存

メールアドレスと鍵を使ってstoreにアクセス

※ データはオブジェクト
※ keyは保存したjson形式の鍵の中のprivate_keyを使う
var key = "-----BEGIN PRIVATE KEY-----\n{省略}==\n-----END PRIVATE KEY-----\n",
FirestoreApp.createDocumentWithId("FirstCollection", "FirstDocument", data, email, key, projectId)

データ更新

FirestoreApp.updateDocument("FirstCollection/FirstDocument", data, email, key, projectId)

13
17
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
17

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?