C# Application to Firebase Database - Retrieving Updated Data

In this post we will be going through the way in which you can go about retrieving updated data in Googles Firebase database using a C# application. Retrieving data has been an extremely large request and so its finally here. Please note that if you are wanting to retrieve data that is being posted or inserted in to Firebase the code will need some tweaking and will need to have some changes made. We will be going through this in the next article.

Please also note that all code we run using Firebase is carried out in test mode, meaning there is no authentication, no password or username. Meaning that anyone in the world is able to read and or write to your database if able to retrieve your HTTP request URL. We will be posting another article to cover this and how you could go about setting your authentication settings in Firebase to then go on to making use of the database credentials in order to establish a connection. If you have any special Firebase requests in C# or any request in general please do leave us a message using the online form we have made available via the contact or questions page. We look forward to reading any comments or requests you may have.
If however you are wanting to have some form of authentication added to your project check out the below
Authenticating Your C# Application with the Firebase Database


Be sure to have a read up on some of the other posts we have as you may find them of extreme use. Especially if wanting to remove those random base-64 keys being generated when inserting and updating data. Also find out how to retrieve specific children nodes.The list for which can be found below:
Inserting data in to the Firebase database
Updating data in the Firebase database
Deleting data in Firebase database
Inserting Individual parent and child nodes in to the Firebase database
Removing random base-64 keys from the parent nodes within the Firebase database
Retrieving Individual parent and child nodes from the Firebase database



The retrieval of data in itself can be seen to be something thats pretty straight forward, using a HTTP request and stream reader you can very quickly get hold of the data within Firebase. HOWEVER, the information will always be retrieved in JSON and as seen in the post prior to this we can see that the entire JSON tree is retrieved, click here to read previous post. For those unsure as to what a JSON tree may look like please refer to the below for a very basic example: -



The above could represent the data for an online game whereby the data for an individual user is being held and constantly updated in terms of his score and time, information such as the level and username will be changed only when needed. Retrieving the entire piece of information above is useful although cant be processed further until its being parsed or deserialised in to single variables we can then go about making use of. By doing so, the above would turn 5 individual string variables being ID, Username, Level, Current score and Time.

So we will begin now looking at the code in issue and to start with as usual we will focus on the Include Headers being used. The majority of headers being used are those that have been used in the previous blogs with the exception of one.



In this example we make use of the Newton.Json.Linq namespace. Its use to us is of extreme importance as it enables us the ability to effectively retrieve data in Json, parse it and the go about creating individual strings. All other headings are those that are included in previous posts to do with the inserting and updating of data in to Firebase using C#. Not all are exactly necessary but useful to have especially if wanting to further extend the functionality of this code.






We first go about creating a string named URL which will be used in our HTTP web request, this link should contain the URL of your Firebase project followed by /.json. Please ensure you have entered this in correctly before proceeding onwards. In the next line we then go on to making a request to our Firebase project online via the use of a HTTP web request where the URL string is then put to use. A side note the URL string doesnt need to be created, instead you can go about entering in the actual URL within the web request. We then create a HTTP response, making use of of a stream reader we are then able to read the text in firebase which by default will give you the entire Json tree of data you have. With the Newton.Json.Linq namespace we can make use of the JObect.Parse class to parse the Json data received. Once parsed we then move on to declaring a new string names Second. This second variable will be the equivalent of the node named LatestSecond within Json. Which is then displayed in the console.



If your variable is named something other than LatestSecond which is more than likely be sure to then make the appropriate changes to the second to last line in the above snippet. This should match exactly as that seen in firebase refer to the below for a better illustration



The above is an example of what your data structure may look like in firebase where the score is a number that is continuously being incremented. And so if wanting to retrieve the updated of the score you would go about replacing the word LatestSecond with Score. If you are having any issues with the do send us a message via the contact page so that we may be able to provide assistance. We will have a comments section coming soon where we expect all to be discussing, asking and answering.



The full source code for this project can be found below, when inserting please be sure you have installed the NetGU Package in visual studio as you will face problems if the package isnt already installed. Feel free to visit contact page and leave us a message or any feedback you may have. Subscribe to the YouTube channel, follow us on instagram and join the mailing list. Become part of the movement and share with all of those who may be interested. The more support we have the more frequent we can post new articles, we need your help!

Be sure to have a read up on some of the other posts we have as you may find them of extreme use. Especially if wanting to remove those random base-64 keys being generated when inserting and updating data. Also find out how to retrieve specific children nodes.The list for which can be found below:
Inserting data in to the Firebase database
Updating data in the Firebase database
Deleting data in Firebase database
Inserting Individual parent and child nodes in to the Firebase database
Removing random base-64 keys from the parent nodes within the Firebase database
Retrieving Individual parent and child nodes from the Firebase database





"If you ever talk to a great programmer, you will find they know their tools like an artist knows their paintbrushes."
-B.Gates-


"Computers themselves, and software yet to be developed, will revolutionize the way we learn."
-S.Jobs-

SEO Introduction - Black Hat & White Hat SEO

SEO, How? What? Why? A very quick brief on SEO and the difference between the Black hat and White hat approach. The start of a new saga have a quick read and let us know what you think.


Authenticating Your C# Application with the Firebase Database

In todays post we will be going through one of the ways we can have some form of basic authentication implemented in to any project. This form of authentication can be applied wherever you want, whether it be you are Posting, Patching, Deleting and more. Keep your project safe and allow only those you want to have permission to access data within your database.


C# Application to Firebase Database - Retrieving The Entire JSON Tree

In todays article we will go through how to retrieve all data from Googles Firebase database using a C# application, this article will not however go through the retrieving specific or individual data but rather we will be returning the entire Json tree. Again as explained in all posts and articles before there is no database authentication being used in this example.