Everyone and welcome back.
Jenny be here with soapstar.
And this is our final lesson we are going to cover Twitter log.
All right.
So let's get to it and jump back into our browser here.
We are currently in our firebase con. We open up a new tab hearing an say firebase off Twitter iOS.
So much for that.
And we should get this first link here.
And we're going to come over here to where it says register your app as a developer application.
All right.
And we are going to create a new app here so I already got this one that I was working on for at testing's.
I want to create a new app and we're going to say name I'm going to say firebase social slopes and just
put in a description this is a demo for firebase authentication.
Website.
So you don't have to have a Web site like a real web site.
You could put anything here in fact I think if we let me see here is here developers documentation for
Twitter.
They say Let me see here.
So I'm not sure where it was but they said you could even put something like a h t t p place holder
dot com you know put anything there.
And then the callback you are.
We're not going to put anything there quite yet.
So when you say yes I've read and create your Twitter application already has been created.
So now that we have our app here in our settings I guess it's keys and access tokens here we have our
key and our secrets we want to copy our key and we're going to go back to our firebase console and we're
going to activate our Twitter site and provide it here.
I say enable and paste our key and then I'm going to go back to our app and grab our secret and paste
that here for API secret.
Now I'm going to copy our callback Eurail here is a copy callback you are going to see save.
And then we are going to come into our settings and we want our callback you are all here going to paste
that.
And I'm going to say update settings.
All right.
Looking pretty good.
Let's check out our documentation here again.
So that's all done.
Let's look at our Twitter developer documentation and one of the things that we're going to need here
is in our prerequisites we need to add a Twitter kit to your health scheme to our app.
So just like we have for our Facebook and Google that your whole scheme is Twitter kidda followed by
our consumer key when it copy our consumer key again here right here.
And then let's jump into X code come up here to our project and see here in our target and info your
types here we go.
And I'm going to say right here the see what was it going back to the documentation here.
OK.
Twitter kit all lower cap lower case and then a dash and then our consumer key.
All right.
So Twitter kit dash and then I'm going to paste our consumer key here.
All right.
That looks good.
And let's see what else we have here.
You know let's check out the rest of this see you or else scheme set up right so it looks like we need
to add a couple of properties to our Ellis application queries scheme.
We need Twitter and Twitter off.
Let's go ahead and add those as well.
So that's here in our photo op list and right here Ellis application query schemes we have these four
currently so we can add one.
And this was the what was it again Twitter and Twitter off.
OK.
So here we go Twitter
and then add another one and this is Twitter off right.
There you go.
So I think that's pretty good.
Let's go ahead and jump into our app delegate now and do some work here.
First things first we need to import to Turcott and down here in or did finish lunching with options
or we're going to need to do is we need to do the Twitter.com shared instance start start with consumer
key and the consumer secret.
So we are going to need to get the consumer key and consumer secret from the info dictionary key which
we haven't actually added to our input up the list yet.
So let's go ahead and do that.
So to do that we're going to get into our full list and I'm going to add a couple of fields here.
This is going to be called the consumer key.
That's going to be a string I'm going to add another one and this is going to be consumer secret and
then we're in a grab from our Twitter application here the consumer key piece that right here and then
our consumer secret and going to paste that right here.
I just want to save that and then back in our Abdellah get we can get our key and secrets and we say
let me equal to bundle dot main dot object for info dictionary key and the key is let's see here consumer
key.
So where are you setting key equal to this value right here.
All right.
And then we need the secret as well as say secret equal and bundled that main dot object for dictionary
key.
And this is consumer secret.
All right.
And then those are of type.
Any right now so we need to cast them to strings.
We'll see if flat key is equal to key as a string.
And if you let a secret equal to secret as a string then we're going to say Twitter dot shared instance
that this start with consumer key and we Pessin key and consumer secret and we pass in secret.
All right.
Now Twitter is all started up and ready to go.
And the last thing we need to do here in the app delegate is come down here to our return Google and
return Facebook now we need a return Twitters.
When I say let me turn Twitter equal and this is actually pretty close to the same as the FBI's STK
when to copy this and paste it here.
So instead of the SDK application delegate it is just Twitter.
There you go.
And here we are going to and the return of Twitter as well.
All right very good.
So far we have created our Twitter app.
We have set up our info up list and we have our app and delegate all set up.
So now the last thing to do is actually add our buttons and handle all of that logic into view controller
DOS with file.
So let's jump into it.
So if we check out the documentation here for getting started see here.
We want the log in with Twitter.
You'll see here it says that the simplest way to authenticate a user is using the Twitter log in button.
And so what they do they just instantiate encode a log in and then add it to the view.
So we thought well we'll do that as well as our custom button like we've been doing through that here
in view did.
We are going to do the programmatic button first we're going to say let log in Twitter by an equal and
then see here do we have we imported Twitter yet.
No we've got to import Twitter say import Twitter.
There we go.
And now we can say t w t our log in and there we go up and then we're going to have a log in completion
for it where we get the session and the error and we're just going to say if let error is equal to error
then we'll Debug.
Print.
Well say could not log in Twitter.
And then we'll print out the error.
All righty.
Next up we just got to get the credential.
Like usual we're going to say.
And that's from these sessions we're going to see if flet session is equal to session lit credential
equal Twitter off provider dot cadential.
And then we need to just pass in the tokens so session that Ophth token with the secret session that
auth token secret and now we have our credentials we just pass that into firebase we see firebase log
in and we pass in the credential and we need self since we are of course any closure.
All right so now that we have a problematic regenerated button here we need to add it to a view.
All right so what we could do is like they do and the documentation is they just add it to the view
controller's view and smack dab in the center so it looks like this.
Another thing that you could do you could do that or you could.
One thing that we could do is we could just add another view here you I view and put that in here.
And at our constraints like we've been doing 20 20 and 20 and setting the height to 40 them will go
ahead and add our next button as well the custom Twitter log and button that we've been doing.
And I'm going to set this to 20 8 from the top and 20 from the right and changing the height to 40 and
add those four constraints and then I'm going to change the text of the button to log in Twitter.
I you change the text color to white and I'm going to change the background color to a light blue.
And if you want that color that is hecks three a and one F2 I randomly save this and open up.
Are you controlling the assistant editor so that we can make some outlets and actions.
So slutting our view here I'm going to say Twitter but you know it's an outlet when I say connect and
then for our button here I'm going to create a new little section for Twitter here under the Facebook
I'm going to say Twitter and I'm going to create an IB action for our button here.
And this is in action.
When I say custom Twitter tapped and connect I'm very good going to calls or assistant editor go back
into our view control it swift and right here after we create our button in code then we are going to
add that button to our Twitter button view that we just created here.
So when you say Twitter button you add some view and the view that we are adding is the log in Twitter
button and then I'm going to align that to the center.
So I want to say you love intuit or button dot center dot x is equal to the Twitter button view data
center dot X so it can run there and just see how it looks.
Right.
Looks good.
Go ahead and click on this and see what happens.
Check it out.
We are launching here.
All right so username or e-mail.
Go ahead and put in my email and password here.
When you say authorized app and boom we are back and we are logged in.
All right.
So simple as that once you got your Twitter app set up once you have all of your info up close with
your schemes and the consumer key consumer secret.
Once you set up your app delegate and then all you need to do is create this log and Twitter button
and boom.
Pretty nice.
So last thing I want to show you is we have our custom Twitter button down here.
Let's see.
Twitter tapped and pretty much all we do here is we just say Twitter and Dot shared instance dot loggin
and we have a completion here so we're going to session and error and then we can actually just copy
what we have in our other Twitter button here.
And paste that right here.
And let's run that again make sure that works.
I'm going to log out and then log back in with this custom Twitter button and looks like it is working
just as expected.
All right perfect.
All right so there we have it.
We have covered in depth these three social logons Google Facebook and Twitter and now you are able
to implement this in any of your apps.
Now you'll notice that we didn't do anything else after we log in but that is very easily handled.
For instance here in your let's see here in your office to change listener.
Once we log in instead of just saying self user input off label and putting up a label here you could
do something like perform Segway and then you could perform Segway to your next to me.
Once we have logged in and then throughout the rest of your app you're locked in and you have access
to your users information.
So there we have it.
I hope you guys learned a lot going through this course learning how to implement the firebase social
logons.
All right so my challenge to you is to implement social log in and one of your own apps and make it
so that once you log in you actually continue with the rest of your app.
You will segue to your your main PC and continue from there.
All right.
So I hope you guys had a lot of fun learning about social log in and keep it up and I'll see you around.