I am working with firebase to get data from the nest api. I had a working test setup where I was able to receive data, and set values. Now I am working in python to get a little server running that automatic updates my database. I had data a few days back. But today I wanted to work on it, and i didn't receive any data anymore. So I checked my test setup. And that one is neither getting any data, But I am still able to send data.
This is the javascript I use for my test setup.
var dataRef = new Firebase('wss://developer-api.nest.com/');
dataRef.authWithCustomToken("{{user.token}}", function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Login Succeeded!", authData);
}
});
dataRef.on('value', function(snapshot){
console.log(snapshot.val());
});
It should work. But can it be that something broke with the update?
I also created an new client but that did not work either.
An other python application that i am running with nest is using the websocket-client an that one still works. But for the application i am now working on i need to get data from different accounts. If i use the websocket-client it wil use to much resources. so that is not an option.
Hope someone can help me.
Firebase upgraded their client recently. Since Nest runs its own instance of Firebase, make sure that you are using one of the supported Firebase versions available here and not that latest version.
https://developer.nest.com/documentation/cloud/firebase-client-libraries
Related
I am using vue-2.And want to do shallow query for firebase realtime database by fetching API.But While running on development server ,it shows CORS blocked. What should I do?
PS: I am also using vuefire
created(){
var apiUrl = 'https://console.firebase.google.com/u/4/project/enajori-45094/database/enajori-45094/data/Admin/Data%20Collection/Paying%20Guest';
fetch(apiUrl).then(response => {
return response.json();
}).then(data => {
console.log(data);
}).catch(err => {
console.log(err);
});
}
Cors error i am receiving
Firebase REST-Api only reacts to HTTPS-Requests. If your localhost doesen't have SSL enabled your requests will fail no matter what your try. The URI also need to end with the the table's name like something.json
And you realy should use the Firebase SDK - it's the smoother way.
It's entirely unclear to me why you would want to use a URL to the Firebase console to access the database. Console URLs are for human consumption, not for programs.
You should use the provided javascript SDK to access data. It will work around CORS issues for you automatically, and give you a much cleaner way to read and write data. If you can't use the SDK, you can always try the REST API. Just don't depend on those console URLs at all.
Now I use ReactJs and I want to save large data in local, I try to look for a SQLite for reactJs but I can't find it, all about SQLite for react-native, Please give me information how to save large data in local using reactJs.
Thanks.
You're saying locally but in one of your comments you are concerned about the amount of data that can be saved..
If you're not looking for the overhead of a full-scale database solution, you could use Firebase RealTime Database; It's free for up to 1 gb of data and super easy to set up.
https://firebase.google.com/products/realtime-database/
You'll define a schema for your database through Firebase's console then copy and paste the config into your code then run an intitalization script and then use firebase refs to access the API (see below for simple example)
npm install firebase
import firebase from 'firebase';
var config = {
... {paste-from-firebase}
};
writeUserData(name, priority){
firebase.database().ref('users').push({
name,
priority
}).then((data)=>{
//success callback
console.log('data' , data)
}).catch((error)=>{
//error callback
console.log('error ' , error)
})
}
componentDidMount(){
// initialize firebase
if (!firebase.apps.length) {
firebase.initializeApp(config);
}
// an example of writing user data to the db
this.writeUserData('John', 'normal')
}
If you want to implement SQLite in your application, you will need to implement it server-side and not client-side for several reasons; the most important being security... Take a look at this SO answer:
Is it possible to access an SQLite database from JavaScript?
Apparently, there's also another relatively newer option called IndexedDB that some browsers support to locally store large amounts of structured data;
https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API/Using_IndexedDB
I would use firebase. It's well-supported, made by Google, and very easy to get set up with.
Suddenly my code for adding new documents to Firestore is not working and not returning an error. I thought perhaps it was a network issue but Authentication and creating new users is working fine. My network connection is also quite solid.
[EDIT] I've switched on debug mode and a call to Firestore is made with a documentChange request and the correct data fields. The document is never created though. I am on the latest Firestore release.
I tried this simplified add to my collection:
firebase.firestore().collection('biff').add({
boff: 0,
baff: 5
}).catch(function(error) {
console.error('There was an error uploading a file to Cloud Storage:', error);
});
Here are my security rules: (I also tried completely public writing)
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if request.auth.uid != null;
}
}
}
There are no error messages generated and the new document never appears in my collection. I can authenticate and create new users. Is it possible that authentication is live but somehow my firebase SDK thinks that there is no connection to firestore so its queueing up the documnent writes?
[UPDATE] I noticed that an earlier alpha version of my frontend was still able to write new documents. When I listed the projects firebase knew about in the CLI it listed an older firebase project. So I did 'firebase use --add' and chose my new firebase project and then did a 'firebase init' to reset everything except my index.html. I then did a 'firebase deploy' and lo and behold my deployed version is able to write new documents. My localhost version still is not able to write them though. So very odd. So I am half way there with a solution. All ideas welcome on whats happening on my local machine to stop writes still ...
Once I used a button instead of a form submit to trigger the routine with the document.add then it all worked from localhost, server and mobile. In the broken version the form would continue processing and leave the user in the main view in a state where that url and all urls afterwards had a parameter (?topic=Business) appended to them. From then on the document.add would no longer work. By moving to a button and using e.preventDefault it now works every time and all the urls remain clear. (no idea why this side effect wedged firestore add)
var postOfferElement = document.getElementById('postoffer');
postOfferElement.addEventListener('click', function(e) {
e.preventDefault();
saveOffer();
});
In saveOffer:
firebase.firestore().collection('offers').add({
created: firebase.firestore.FieldValue.serverTimestamp(),
owner: getUserID(),
name: getUserName(),
pic: getProfilePicUrl(),
completes: 0,
favs: 0,
offer: offerText,
topic: topicText,
exp: expText
});
I've been trying to work with Ionic push notifications and everything went well untill I had to store the Device token which I recieved. I've been following every step the tutorial gave me so I don't see any wrong code in my project.
This is my register code:
// kick off the platform web client
Ionic.io();
var push = new Ionic.Push();
// this will give you a fresh user or the previously saved 'current user'
var user = Ionic.User.current();
// if the user doesn't have an id, you'll need to give it one.
if (!user.id) {
user.id = Ionic.User.anonymousId();
}
var callback = function (data) {
console.log('Registered token:', data.token); // is not empty
console.log(data.token);
push.addTokenToUser(user);
user.save();
}
push.register(callback);
I get the following error:
Ionic Push Token: dev tokens cannot be saved to a user as they are a temporary resource: ionic.io.bundle.min.js (2,5965).
When I'm trying to execute:
push.addTokenToUser(user);
My ionic interface looks this way:
I'm actually expecting my device token to get stored in there. But that isn't the case..
I hope some of you guys have seen this problem before and might be able to help me.
Greetings!
I had this problem until I discovered that I was using an old version of cordova (v.4). Anything below v. 5 does not work properly with Ionic (current Cordova version as of writing is 6.0.0).
npm update -g cordova
Everything worked as documented after that.
Put Ionic in production mode, so it use the certificate you uploaded. (But still in dev mode for devices)
$ ionic push --production-mode=n
In the ember guides on models it says (1) :
Ember Data is also designed to work with streaming APIs like socket.io, Firebase, or WebSockets. You can open a socket to your server and push changes to records into the store whenever they occur.
I tried writing a custom adapter that uses a websocket but i'm not getting very far. I couldn't find any working examples anywhere.
This is my totally unfinished prototype:
DS.WSAdapter = DS.Adapter.extend(Ember.Evented, {
websocket: undefined,
init: function () {
if(this.websocket === undefined)
{
this.websocket = new WebSocket('ws://localhost:8887');
this.websocket.onopen = function(e) {
console.log("Connection established!");
};
this.websocket.onmessage = function(e) {
// What to do here?
};
}
this._loadData();
},
//....
Can somone please help me with the websocket adapter?
My main problem is that I have no clue what to do when the websocket.onmessage() gets executed. I can't even access the store (using DS.get('defaultStore')) or anything
I don't have experience working directly with sockets in Ember, however I have recently completed an Ember Data + Firebase adapter which should follow very similar methodologies.
You should, at the least, be able to use it as inspiration:
https://github.com/sandersonet/ember-data-firebase
Firebase does provide an additional layer of abstraction from the sockets underneath, but the methodologies are very similar.
Have a look at http://emberjs.com/guides/models/frequently-asked-questions/#toc_how-do-i-inform-ember-data-about-new-records-created-on-the-backend
Some applications may want to add or update records in the store
without requesting the record via store.find. To accomplish this you
can use the DS.Store's push, pushPayload, or update methods. This is
useful for web applications that have a channel (such as SSE or Web
Sockets) to notify it of new or updated records on the backend.
Basically, you need to deserialize data you receive in your onmessage hook and push new objects to the data store using store.push('model', record) or alternative methods.