This video is to implement a login with Facebook in an Android application. In a previous video we saw the Facebook SDK configuration on a project in Android Studio where we created an application called “Today” and will now be our starting point. Once we set up our project we will begin implementation. One of the easiest ways to start is to use the component session LoginButton providing us with Facebook, and represents the button log that will put our design. Currently in our application we have a single Activity to be presented the main screen of our application and for now only has a text of welcome. We will create a new Activity for login. We use the wizard to create an empty Activity and LoginActivity call. Once created we add to the LoginButton component design. Having already He set Facebook SDK in the project, it shall be recognized without problems. For example we will place the button at the center of the screen and let’s give giving some height upper and lower padding, and the attribute Height is not recognized in this version of the component. The ID we put him It is LoginButton with which we get a reference LoginActivity. To detect the actions or events of this button will use the class CallbackManager, which can create in the onCreate method of the Activity that will handle the login and know that actions must onActivityResult be in the method receiving them, then we make the login button use this callback, and with this we we have three possible outcomes. When the login is successful, the method will run onSuccess and we can access basic information such as the token of the session with loginResult object when login is canceled onCancel execute the method and when some type of error occurs as the onError connection or other method will run. If we ask if we logged in, we can use this accessToken method of the class and if we take action log to a button or a menu you can use the following line, both lines can be accessed from any part of our application. Returning to our project will put the LoginButton and CallbackManager as attributes our Activity, initialise both in the onCreate method and then We assign the callback created our button with three methods that have we need to handle events at login. Other than that we need the method onActivityResult in our Activity that is where actions come and we have to redirect the callbackManager. Now we could decide what to do different cases. When the login with Facebook is valid what usually done is to go to the main screen of the application, in our MainActivity case, so let’s create a method that does just that, goMainScreen call or go to the main screen, which will the necessary lines to open the Activity with flags that allow me my main screen is the only running Activity This is done to avoid the problem that when he or main screen and press the back button not my login screen and go out directly from the application as it should be. On the other hand if the operation is canceled in our method onCancel we could display a message to the user, for example in a SnackBar or a Toast. In this case we will use a Toast and put on a String resource that we want to show. In the same way when some type of error occurs is we will inform the user, We could also use the object to display more FacebookException error details. With this we have the functionality of the login screen, but the screen always starts when running the application for the first time is MainActivity, there are going to ask if we logged or not, accessToken this method can have the current token, if it is null It means I have logged in, when this happens we will want I go to the login screen to perform the process. We created a method for LoginActivity start with the same flags for avoid problems, we used before. Additionally this, when the user is on the main screen means having a session therefore has to be the logout option at some point, this action may be a button or a menu within the application, for our example we will create simple button on the main screen and as we know another way to give me action button He is using the onclick attribute and the wizard already have a method in Java. Here we set the line to log that can be used in any part of our application and when we closed session which generally want is to quit the application and go to the login screen again, then we can call our method and created to go to the login screen and with that we have implemented in functionality Login with Facebook in our application. Running the application our emulator, we can see that, not having session shown above LoginActivity. One of the characteristics of LoginButton Facebook is already internationalized, ie the text displayed on the button It is on the phone language pressing the component decides whether to open the native Facebook application, if we have installed or open version Web if we do not, on the other hand if we end amidst the beginning of process session, we can see that we are showing that we put Toast. Now let’s make a start valid session. We enter the email and password of a valid user of Facebook and we press log, then the screen appears permissions, the permissions that are granting the application for use or displays a message if you already have authorized above. Once successfully entered you go to the main screen of my application which has the text of welcome, this session will remain until we close session. We can even reset the device or completely close the application and when we return to join the session will continue. Now we will press the button to log out and will go to the screen login and will remain there until you log in again. To prove we close the application and re-enter again and we keep in the login screen. Anything else we need to know the time of login are the permissions you grant our applications, default every time the user logs on us provides access to your public profile names, profile picture, gender, between others. If we want permission to access other information, have readable and we tell our LoginButton, putting what we want exactly permissions for example email and friends list who also they use the application, do not require revision, if we want to know Like what pages did the user application must undergo a review, revision can try 7 to 14 days We can also apply for permits publication, assigns it to our LoginButton in the same way and requires review. For example we will add our application to have permission to get mail mail user, you assign it to our LoginButton with the name permit accurate and re-run the application. We push log in with Facebook, we fill the data of a valid account and we can see on the information that was added permission to read mail mail depends on the application being developed can want to make use of other permits, for most it is sufficient to identify the user. In the following videos will continue the series of Firebase for authentication. The code is used in the video description. Thank you for your attention, my name is Daniel and until the next video.