I am trying to develop an android app using nativescript and firebase as backend.To use Firebase I am using this plugin. I am trying to use Firestore for my app .I get this error each time I try to start the app.When I used realtime database ,I was easily able to access all the data, so this is not a network or configuration issue. Below is the code I am using to connet firebase and use firestore.
firebase.initializeApp({}).then((data)=>{
console.log(data) //it prints the databaseURL and it is correct.
});
var db = firebase.firestore();
db.collection("users").doc('<docKey>').get().then((doc) => {
if (doc.exists) {
this.data =doc.data();
} else{
this.data ="No such document!";
}
}).catch((error) => {
console.log(error);
});
Did you try Googling it? Please do and provide some pointers here if you have time: https://www.google.com/search?q=com.google.firebase.firestore.FirebaseFirestoreException%3A+Failed+to+get+document+because+the+client+is+offline.&oq=com.google.firebase.firestore.FirebaseFirestoreException%3A+Failed+to+get+document+because+the+client+is+offline
Yes Eddy, I did some initial research but didn't find any valuable solution. Below are some links where this same issue is raised.
Still waiting for some solution
Here it is said a fix was rolled out but still the issue is faced by some users
I guess this is happening for Android App development only as most of the above issue was raised while developing for android.
Solution to this issue will be really a great help.
Thanks.
So do you think this is an issue with the plugin, or the Firebase Android SDK?
I am also in the same dilemma. I have raised a issue in firebase support also. Let me get in touch with them and discuss the issue and will update here accordingly. But in the meantime it would be great if you provide some insights regarding this or workaround.
If you have changed the project id but not changed in firebase.initializeApp, you'll get this same error. Please check and see if that's the case.
I got this problem on Android. It happens after reconnecting to the internet, even though any other network calls work fine.
I solved it after modifing security rules on that document
Can you share what you changes exactly?
@jacopo69 Can you please share what you modified in security rules?
Simply check if you have permissions to access your document. In my case I forgot to set the read permission:
match /channels/{channel} {
allow read: if request.auth.uid != null;
}
I had the same error, when I used wrong path to the document. Anyway the error message is misleading.
I solved this issue after using addOnSuccessListener instead of OnCompleteListener. OnCompleteListener is always called if the task was completed successfully, or there was an error. So we should check the task for success or failure. Or we can split it up into an onSuccess and onFailure callbacks that get invoked depending on the status of the task.
@shuvojit007 I agree that having both a 'success'/'failure' and 'complete' listener is superfluous/confusing, so I removed two 'failure' listeners from the code. However (regardless this change), when 'then' and 'catch' have been wired your app should be notified properly in case of trouble:
If you meant something completely different then please post a code snippet or repo as an example.
i'm facing this issue on kitkat when adding inApp messaging dependency
I solved this issue after using addOnSuccessListener instead of OnCompleteListener. OnCompleteListener is always called if the task was completed successfully, or there was an error. So we should check the task for success or failure. Or we can split it up into an onSuccess and onFailure callbacks that get invoked depending on the status of the task.
This issue seems to be related to the addOnCompleteListener only ,I also had this error ,and eventually resolved after I used the onSuccess and onFailure listeners instead
I'm facing this same issue right now. I'm not use oncomplete listener. I'm just using a straight up call to the database. This only happens sometimes for some users, and seems to fix itself when they login and log out. Here is the call to the database that is erroring out. Has anyone figured this out?
DocumentSnapshot userLivestream = await Firestore.instance.collection('livestreams').document(userId).get();
Did you try the above workaround suggested by others, using addOnSuccessListener instead of OnCompleteListener.
If you have changed the project id but not changed in firebase.initializeApp, you'll get this same error. Please check and see if that's the case.
how to know where does the project id lie ?
Did you try Googling it? Please do and provide some pointers here if you have time: https://www.google.com/search?q=com.google.firebase.firestore.FirebaseFirestoreException%3A+Failed+to+get+document+because+the+client+is+offline.&oq=com.google.firebase.firestore.FirebaseFirestoreException%3A+Failed+to+get+document+because+the+client+is+offline
Hey Eddy, guess what, your snarky comment is at the top of google searches.
@elis What's so snarky about asking folks to help me figuring out the cause of an issue? Do you have any idea how hard it is to triage issues like this one?
@UD-UD How did you solve this issue? I am facing same error and nothing from Google could solve it. Looking for your help if possible.
Same error on android using kotlin. My app works well but a user is facing that bug. I'm using success and failure listeners. The user has the same app version than me, everything is the same. I can login with his account and the app works but on his phone he cannot load any data. He is able to login successfully by the way. Anyway, what does "the client is offline" mean? does it mean that firestore server is down? if so, why i'm able to load data but my user cannot? he's facing the problem since one week ago...
This is a very weird issue. My web application is throwing the reported error in the browser's console but the Firebase API is fetching data most of the time(not always). Whenever it is not, it throws the reported error message.
Used rules in my app -
{
"rules": {
".read": true,
".write": true,
}
}
The same error happened yesterday as well but disappeared after a few seconds and started working properly.
Most helpful comment
Simply check if you have permissions to access your document. In my case I forgot to set the read permission: