You set the security rules for your Firebase realtime database in Firebase (Rules).
Look also there for sign in methods available (Authentication)
You use the Firebase Authentication extension to connect AI2 users to your Firebase database
You should be able to follow the visuals without need to translation, most people have.
However, just for fun:
I grabbed the audio using youtube-dl
Converted it to text using the IBM speech to text online service
Dropped the text into Google Translate
Here is a transcription as text document in English (with the text in Spanish below). You have to “read between the lines” !
Since I cannot use user authentications using the FirebaseDB component in AI, I thought of using the Web component to access the database instead using PUT and GET requests. In that way, I could use authentication acquired using the Firebase Authentication V.3.0 extension.
I was working on it when I found this tutorial achieving similar thing!
Here’s the link.
The only issue with the tutorial is that the custom DataChanged procedure is only triggered after the server sends response to a PUT request. In other words, the custom DataChanged method is not globally triggered. So if you change the data in the same database from a different phone running the app, the DataChanged block won’t be triggered on other instances.
EDIT: It seems the only thing needed in the native FirebaseDB component is the feature of dynamically setting the token field.
MIT considers the code they use to access FirebaseDB to be deprecated. Google deprecated the solution MIT uses to access Firebase some time ago. Jeff indicates Google could pull the rug out from under the current solution at any time. MIT decided a while ago they wouldn't continue developing the tool.
...would they be able to do it? I don't know. MIT provided CloudDB as an alternative to Firebase because they expect the way AI2 links presently might not be possible soon. So beware. FB is a nice tool but it might disappear like Fusion tables. or you might get lucky and Google doesn't change anything for a long time.
@TIMAI2 Great tutorial! Thanks! We now just need to add a “DataChanged” event-like functionality. How does the “DataChanged” event achieve that? IMO if it’s achievable through blocks, then we might also be able to implement it using Web / JavaScript etc.
I have worked up the dataChanged scenario using javascript. This works fine in my computer browser, but I have some more work to do on the authentication to get it working in a webview (to feed the data back with a webviewstring). Watch this space…
Here is the completed html which can be used for the dataChanged event. Firebase returns everything, not the individual changed/added/removed item/s, so work needs to be done when the json is received back through the webviewstring. I have the firebase js scripts stored in the assets along with the html file. All the user details and the firebase config, comes through the webviewstring.
<!DOCTYPE html>
<html>
<meta name=“viewport” content=“width=device-width, initial-scale=1.0”>
<meta charset="utf-8">
<head>
<title>DataChanged</title>
<script src="firebase-app.js"></script>
<script src="firebase-auth.js"></script>
<script src="firebase-database.js"></script>
</head>
<body>
<script>
var wvstr = window.AppInventor.getWebViewString();
var email = wvstr.split(",")[0];
var pass = wvstr.split(",")[1];
var setPB = wvstr.split(",")[2];
var uid = wvstr.split(",")[3];
var firebaseConfig = {
apiKey: wvstr.split(",")[4],
authDomain: wvstr.split(",")[5],
databaseURL: wvstr.split(",")[6],
projectId: wvstr.split(",")[7],
storageBucket: wvstr.split(",")[8],
};
firebase.initializeApp(firebaseConfig);
var auth = firebase.auth();
auth.signInWithEmailAndPassword(email,pass);
auth.onAuthStateChanged(function(user) {
if (user) {
// User is signed in.
getData();
} else {
// No user is signed in. <Use error message here>
}
});
function getData() {
var dbRefObject = firebase.database().ref().child(setPB +"/"+ uid);
dbRefObject.on('value', snap => {
window.AppInventor.setWebViewString(JSON.stringify(snap.val(), null, 3));
});
}
</script>
</body>
</html>
FireBase is accessible by two methods:
• Through the SDK (which seems to be the method used by the native blocks of the experimental FireBase component of AppInventor), and
• Through the REST API (HTTPS requests, which AppInventor can also manage with the Web component):
In practical terms, the difference seems to be that:
In the first way (in addition to simple requests to read and write to the DB), also allows setting a listener to the data base node: The FireBase1 .DataChanged block automatically receives changes (made by others to the database child node to which the ProjectBucket is aiming), and allows information updating, or even real-time communications between Apps.
But those requests are not authenticated, and (even with the available extensions) either you can’t secure de database with rules that prevent universal access to sensible nodes; or you can’t set up a listener on the protected ones.
The second way allows sending authenticated requests from AppInventor apps to the Realtime Database REST API, as simple as passing the ID token (generated and received when logging in with the authentication extension) as the auth=<ID_TOKEN> query string parameter. This would solve the problem of access to nodes restricted by rules for authorized users only.
But, how can I set up a listener with http rest? (so that the app receives data updates from a protected node).
This is a handicap that I’m facing in a several years old project.
Can anybody help?