0

在火力控制檯我已經設定在數據庫中的以下規則:經由應用程序腳本谷歌認證與谷歌擴展清單

enter image description here

和下面是谷歌傳播片腳本編輯器

enter image description here

由於任何一個可以寫入數據的基礎上,不存在許可所需要的直到這裏才能寫入數據庫。

現在我想只有一個用戶能夠寫入到數據庫中,所以我改變了規則:

{ 
    "rules": { 
    ".read": true, 
    ".write": "'User_UID_xyz' === auth.uid" 
    } 
} 

我登錄到帳戶,用戶ID 'User_UID_xyz',並在谷歌Spreed運行相同的腳本Sheet。但我得到的權限被拒絕問題。那麼,我需要讓用戶在這裏進行身份驗證?但它已登錄到FireBase進行驗證的帳戶。

///////////////////////////////
///////////// //////////////
此外,我已經通過鏈接:
https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/using-secured-client-authentication-for-real-time-read-and-write-calls 但我搞糊塗了。我爲什麼要在這裏使用Web App?

回答

2

所有對數據庫的服務器端調用都被認爲是「admin」,並且可以讀寫數據庫中的任何位置。連接到數據庫時,您的示例代碼缺少Firebase祕密。它應該看起來像:

FirebaseApp.getDatabaseByUrl(firebaseURL, secret); 

您可以在項目設置的數據庫選項卡中找到祕密。

enter image description here enter image description here

至於那篇文章中,它是專門寫了關於Google Apps腳本網絡應用程序。另一篇文章描述了服務器端調用,雖然它是谷歌IO之前的版本,並且接口已經改變,但API調用仍然是一樣的。

https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/read-and-write-data-in-firebase-from-apps-script

+0

它工作。非常感謝 –