Facebook Module Using EasySocial Oauth2.0 Module

Hafiz Waleed Hussain
U Want To Learn
Published in
3 min readDec 13, 2014

Hi Guys. Now that is the next part of our Social Network series. In this module we are using EasySocial Oauth2.0 module and EasySocialFacebook module for Android. So first I recommend you will read the Android Oauth2.0 tutorial.

OK. I am using Android Studio 1.0 for this series.

Motivation:

First read motivation of Android Oauth2.0 tutorial. After that append this “OK Guys ready to save time”. :)

1. Download EasySocial Module from Github.

2. Download EasySocialFacebook from Github.

3. Create a new project.

4. Add modules in our project.

After adding both modules your project will look like the below image.

Project explorer.

5. Add module dependencies.

Now follow same steps, add dependency in “app module” of “EasySocialFacebook module”, after that you will see your project like the below image.

6. [ Hufffffff :). OK now start code HURRAH … ] Open main Activity/Fragment and initialize credential object and get the EasySocialFacebook instance.

Now next, I only show you the codes which are related to the Facebook module. And for complete code you can download code from Github. I will give you the link in the end of the tutorial :).

7. Facebook Authentication.

In above image REQUEST_CODE having any integer value. Which use to handle authentication response in onActivityResult method as shown below.

Note: Focus on line 175 :).

I think here I show you some GUI elements. Otherwise tutorial start boring :P . Now when we follow the above code. Application will showing us these screens respectively.

8. Get user information from Facebook.

When this method execute. You will see on Mobile screen.

9. Post on Facebook.

When this method execute. You will see on Mobile screen.

10. Extension of Facebook Module.

Now in this part I will show you, how to extend our module functionality. Like I am not adding ‘Facebook Image get functionality’. But if some one want can easily add this functionality.

Note: Here I am not using Plugin or any other design pattern. Because I want this extension also used by those developers which are new in this field. So here I only use two files and try to make very simple and decouple solution.

Open these two files.

  • EasySocialFacebookUrlManager
  • EasySocialFacebook

Now first open EasySocialFacebookUrlManager.java file and add these lines of code.

So very simple, according to your require functionality. You will get the url from developer.facebook.com documententation.

Now open EasySocialFacebook.java file and add these lines of code.

First the code which are showing as black is used to exception handling. So I want to show you the simple and important part of the code, that’s why I remove that from image.

Here you need to follow this convention.

1. Always first you need to add a interface like I added GetUserImageAsUri and declare a one method onComplete(Type data). Here type you choose according to Facebook response. Like if you overview other methods, I use String on some places and JSONObject on some places because I got that from Facebook.

2. Create a void method like I created getUserImageAsUri and declare parameters according to your requirement. But Context and the interface you define is compulsory. This interface used as a Callback, if you feel any difficulty, see other methods which I define here like SendPost, GetUserInfo and after that if you feel little bit difficulty then search on Google :) about Callback interfaces.

So simple, complete. Now Its time to show you how developer call this new method in application and obviously GUI.

So now you get the Url of a user image. You can use in ImageVIew or anywhere but for confirmation I copied that Url and paste into Browser and get the image as shown below.

Complete code of testing app also available on Github.

OK guys. Bye Bye. :)

--

--