Android Question Problem with Firebase

mariosteffen

Member
Licensed User
Longtime User
Hi, folks.
I am developing a system which uses a Firebase database. I am using B4A 8.0 and the libraries are JSON version 1.1, OkHttp version 1.2 and OkHttpUtils2 version 2.61.
Everything works fine if I set the rules of the database as read: true and write: true. I want to change both rules to false, to protect my data. The only functions I want to use of Firebase are to read from and write on the database. I do not need other functions like PUSH messages, for example.
I could not find any example of what parameters I have to specify if I change the rules to false. Does anybody have an example ? My code is below.
I tried to use the CODE tool on this post, but it did not work.

Code to write on the database

Sub PostOnDatabase
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim m As Map = CreateMap(Chave:Conteudo)
Dim jg As JSONGenerator
UrlPost="https://xyzabc.firebaseio.com/abcd.json"
jg.Initialize(m)
Job.PostString(UrlPost, jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "key=" & "HereiITheKeyICopiedFromFirebase")
End Sub

Sub JobDone (Job As HttpJob)
Log(Job)
If Job.Success Then
Log(Job.GetString)
End If
Job.Release
End Sub

Thanks for your help.
 

BillMeyer

Well-Known Member
Licensed User
Longtime User
B4X:
Sub PostOnDatabase
Dim Job As HttpJob
Job.Initialize("fcm", Me)
Dim m As Map = CreateMap(Chave:Conteudo)
Dim jg As JSONGenerator
UrlPost="https://xyzabc.firebaseio.com/abcd.json"
jg.Initialize(m)
Job.PostString(UrlPost, jg.ToString)
Job.GetRequest.SetContentType("application/json;charset=UTF-8")
Job.GetRequest.SetHeader("Authorization", "key=" & "HereiITheKeyICopiedFromFirebase")
End Sub

Sub JobDone (Job As HttpJob)
Log(Job)
If Job.Success Then
Log(Job.GetString)
End If
Job.Release
End Sub

There we are !!
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

mariosteffen

Member
Licensed User
Longtime User
Hi, DonManfred. I want to set authorizations for both options: read and write.
The FALSE on the READ option is to prevent unauthorized people to access your data.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top