[MUSIC PLAYING]
SPEAKER 1: AF 004.
Take one.
DAVID EAST: What's up, everybody?
Welcome back to another episode of #AskFirebase.
My name is David.
And fun fact about me-- I have two small kids,
so I pretty much don't ever sleep.
So we had a lot of great questions
that came in this week.
And if you still have questions that we want answered,
just make sure to go onto G+, Twitter, YouTube,
Stack Overflow, and just use the #AskFirebase,
and we will try to get to them.
But let's dive into what we have this week.
[PHONE CHIMES]
Hello, mom?
SPEAKER 2: Hi, honey.
DAVID EAST: No, Mom I'm recording.
SPEAKER 2: It's Mom.
DAVID EAST: No.
So the first question comes in on Twitter from Mian.
And Mian asks, "What is Dynamic Links?
Can you give me an example?"
Mian, yes I can.
Think about a regular link.
So you go to google.com in your web browser,
and that takes you to Google.
And the great thing about links are
is that you can go to specific parts of a web page.
Let's say you're building a social media app,
and you want to provide a link that maps to a user's profile.
Well, you just go to myapp.com slash the user's ID,
and it takes them right to their profile.
But what do apps do?
Well, in apps, this is known as a deep link.
A deep link can take you to any part of the app
rather than just launching up on the home screen.
So while deep links are really useful,
they can be really difficult to configure cross-platform.
And what happens if the user doesn't
have your app installed?
So dynamic links really fixes this problem.
So a dynamic link is a deep link with behavior
that you can customize.
So if the user clicks on a dynamic link in an iOS app,
or an Android app, or even a web browser,
you can do different things on each platform.
And if the user doesn't have your app installed,
you can change the behavior for that.
So you can take them out to your website, to the Play Store,
or even show them an interstitial,
letting them know how awesome your app is.
And then what's great is that if they download your app,
all the information that is in this link
is still retained when they launch the app.
So you can give them a specific, first-time experience
or send them to the part of the app
that they are actually interested in the first place.
You can view all these statistics in the Firebase
console as well.
So if you want to get started, we
have great documentation on that, which the links are
in the description.
That was a really, really good question, Mian.
[MUSIC PLAYING]
Question time.
That's what's up.
Ivan asked, "What is the scope of a real-time database
listener?
If the app is closed, will the listener still sync the data?"
That's a really, really good question, Ivan.
Actually, if the app is closed, the real-time database
will not synchronize the data.
And that's a good thing.
Because if your app is closed, you
shouldn't be resynchronizing that data,
because that data is downloaded over the network, which
takes up battery.
So if your app is closed, you don't really want to do that,
and you're going to save the user some battery.
But sometimes you are going to want
to be able to refresh the data while the app's
in the background.
And for that, you can use Firebase Cloud Messaging.
Firebase Cloud Messaging allows you
to send downstream messages, and this will wake up the app
and allow you to do a background refresh.
And if you want to see how you can do that,
it's available for both iOS and Android.
Just check out the link in the description on getting started.
Beautiful question, Ivan.
I'm a monkey.
Is there another question in here?
Yeah, there is.
So this next question comes from The Musical Igera.
I think that's what that is.
"I wanted to know if there's a way to associate Firebase
Database with Firebase Storage when
making Firebase Storage rules."
Mom.
So the user wants to know how I map the stuff with Firebase
Storage together.
OK.
So just share the same data structure?
OK.
All right.
Cool.
Thanks.
So this is a really good question,
because security is a big deal.
So the Firebase Database and Firebase Storage
both use references.
And references are mapped to URL paths.
So if you use the same data structure in the Firebase
Database as you do in Firebase Storage,
it makes creating the rules for these really easy,
because the security rules, they map rules at the paths.
For instance, let's say you're storing user data
in the real-time database, and you're storing their photos
in Firebase Storage.
Well, in the real-time database, you can store data at /users/1.
And that's all the data for the user with the UID of 1.
And to get their profile photo, all you have to do is go
to Firebase Storage and store data at /users/1.jpg.
And then now the rules for these two
are really easy, because you're mapping them to the same path.
Fantastic question, The Musical Igera.
Simon simply said that the Firebase Database
is schema-less. (VOICE SPEEDS UP)
Simon simply said that the Firebase
Database is schema-less.
[VIDEO FAST FORWARDS]
So this next question actually was asked three times
this week.
It's-- how do I order data in descending order by date from
the real-time database?
This is a really good question, because by default,
the real-time database returns everything in ascending order.
So to get a good picture of it, let's take
a look at this data structure.
So this is just a list of items, and we have two items--
item 1 and item 2.
You can see that they have a title and a time stamp.
And if I want to get them back by ascending order,
then I can do a query ordered by value
and just pass through the time stamp.
But for descending order, I can do a little trick.
And what I can do, instead of having a Time Stamp field,
I can also have a negative Time Stamp
field that is just the time stamp, but as a negative value.
So now when I do an order by child of the negative time
stamp, it returns everything in descending order.
So good question to all three of you-- Marco, Chris, and to you
on Stack Overflow, Super Silex.
[PHONE CHIMES]
Mom, I'm not done yet.
SPEAKER 2: [INAUDIBLE], I love you.
DAVID EAST: Yeah, I love you too.
SPEAKER 2: [INAUDIBLE].
DAVID EAST: Yeah, I know.
I'm gonna pick it up.
It's cool.
All right.
And another question.
So this next question comes from Rafael.
And Rafael wants to know, "How do you
use Firebase Storage in AngularFire2?"
Hey, Mishko, I got a question on AngularFire2.
Stop calling you?
OK.
That's what you said last time.
Oh, you meant it.
OK.
All right.
So right now AngularFire2 doesn't
have support for Firebase Storage,
and we are working on it.
But what's great about Angular2 is
is that you don't have to use AngularFire2 for everything.
You can actually just use the regular JavaScript SDK.
So let's take a look at this component right here.
In this component, all we have to do in the constructor
is create a storage reference out to our file
and then just call the getDownloadURL method.
And this method returns to us a promise with the string URL.
And then from here, we can store this as a property
to our component.
And then in our template, we can just bind to this image tag
right here to the source, and it will display our image
from Firebase Storage.
So the great thing about Angular2 is
is that you can use the regular Firebase JS library,
and it'll work just fine.
So great question, Rafael.
[WHISPERING]
(IN ROBOTIC VOICE) I'm a question-answering machine.
So this next question comes from Gustavo on Twitter.
"Could you tell us some great companies that use Firebase?"
Well, yes, Gustavo, I would love to.
So PicCollage is a photo collage app
that has more than 120 million downloads,
and they use Firebase.
Also, there is Fabulous, which is
a great habit-breaking app which you should totally
go and download.
Shazam uses Firebase, and like, seriously,
who doesn't know Shazam?
And Skyscanner is also one of the best travel searching apps
out there.
And they use Firebase.
And NPR uses Firebase in their NPR One app.
And if you want to see more companies that use Firebase,
go to our website at firebase.google.com/customers,
and we have a whole list of them there.
So great question, Gustavo.
So this next question comes from Ian.
And Ian asks, "David, are you going
to start using a helmet when you skateboard?"
And yeah, I probably should.
[MUSIC PLAYING]
[RECORD SCRATCHING]
So this last question comes from Francesco on Twitter.
And Francesco asks, "How can I log
in with a custom token using the Firebase Node.js SDK?"
So Francesco, if you want to get started with Node.js
and Firebase, obviously you're going to need your own server,
because you know, it's the Node.js SDK.
But once you have that, it's a pretty simple process.
After you've installed the Node SDK,
there's a method called createCustomToken.
And this takes in a UID.
And this UID is whatever your user's UID is.
So if you're coming from your own Auth
system or your own back-end system,
you populate this with their unique identifier.
And there's also an optional second parameter
to this method, which is additional claims.
And these claims are properties that you can actually use
in the Firebase Security rules.
So this is really powerful for when you're securing your data
in the real-time database.
And this will spit out to you a token
that you're going to send down to the client.
And then once you're on the client, all you have to do
is call the method signInWithCustomToken
with that token, and your user is logged in.
So Francesco, all you have to do is call createCustomToken,
pass in any additional claims, take that token,
send it to the client, and then log in.
Fantastic question.
So that's all the questions this time.
Thank you all so much for sending them in.
And remember, you can just keep sending them in.
Use the hashtag #AskFirebase.
It's been amazing to see these questions that
just benefit the community and everyone around them.
I mean, I honestly have looked at some of the questions,
and I'm like, how would you do that?
And so I've learned a lot, too.
So thank you, everyone.
So if you found this video helpful, please subscribe.
And that's all for this week.
I will see you guys next time on #AskFirebase.
[MUSIC PLAYING]