Facebook is an online social media and social networking service. Users can post comments, share photographs and links to news or other interesting content on the Web, play games, chat live, and even stream live video. Shared content can be made publicly accessible, or it can be shared only among a select group of friends or family, or with a single person. Facebook is also available as Android App.
In this blog, we will be discussing how can we integrate Android Apps with Facebook. We will be using a Facebook Login button to make the user enter our App using their facebook credentials. Developers can extract all the available information that the fb API provides. Steps to develop this can be summarized below -
We will be using Facebook's SDK here which is provided by Facebook's Developers website.
Now, let us begin the development...
Add Dependency to app module also.
Run ‘Sync Gradle’ after you add the dependencies.
In the next Dialog , click on 'Use this package name' as we are developing for testing purposes and will not be working on an app on Google Play.
Visit the link - https://code.google.com/archive/p/openssl-for-windows/downloads - to download the openssl. Open SSL is open source and a software library to be used in applications that need to secure communications over computer networks against eavesdropping or need to ascertain the identity of the party at the other end.
Go to your computer's command Prompt to generate the Key hashes. You will require below commands for generating key hashes.
Enter the Key Hashes into the Key Hashes field.
Go to your app's String's file in the value folder. Enter your app id there as one the strings.
Add a Login button and Logout button for the app in the layout. Login button is provided by the Facebook SDK.
Below is the MainActivity which handles the login button. We use a callBackhandler to be called when user presses the Login button.the callBack is registered within the onCreate method and called on Login button. The callback gets the user's identity confirmed from Facebook and calls the nextActivity method while providing the profile as the argument. In the nextActivity method , profile is used to fetch the details of the user and provided to an Intent(which is to be fired to take user to next Activity - Main2Activity.class).
Main2Activity.class fetches the data from the intent and displays it on its layout. We are showing user's name and display picture here. For downloading the image, we are using DownloadImage.class which is extending AsyncTask.
Layout for Main2Activity.class
Below are the screenshots from the app after development.