问题
In FireBase Console I had set the below rule in the database :
and below is the Script Editor of Google Spread sheet :
Since any one can write into data base, there is no permission required and till here am able to write into database.
Now I want only one user able write into database, so I changed the rule to :
{
"rules": {
".read": true,
".write": "'User_UID_xyz' === auth.uid"
}
}
And I logged-in to account with user id 'User_UID_xyz'
, and running the same script in Google Spreed Sheet. But I am getting the permission denied issue. So, Do I need to make the user authenticate here?? But it is already logged-in to the account which is authenticated by FireBase.
///////////////////////////////
////////////////////////////
Also, I had gone through the link :
https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/using-secured-client-authentication-for-real-time-read-and-write-calls
But I got confuse. Why should I used Web App here??
回答1:
All server side calls to the database are considered "admin" and can read and write to any location in the database. Your example code is missing the firebase secret when connecting to the database. It should look like:
FirebaseApp.getDatabaseByUrl(firebaseURL, secret);
You can find the secret in the database tab of the project settings.
As for that article, It is specifically written about Apps Script web apps. The other article describes server side calls, though it was pre-google IO and the interface has changed, the API calls remane the same.
https://sites.google.com/site/scriptsexamples/new-connectors-to-google-services/firebase/tutorials/read-and-write-data-in-firebase-from-apps-script
来源:https://stackoverflow.com/questions/38949432/google-authentication-with-google-spread-sheet-via-app-script