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

它工作。非常感谢 –