Facebook Module Using EasySocial Oauth2.0 Module

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.

New project.

4. Add modules in our project.

Adding modules.
Adding modules.
Adding module.

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

Project explorer.

5. Add module dependencies.

Adding module dependencies.
Adding module dependencies.
Adding module dependencies.
Adding 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.

Adding module dependencies.

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

Code initialize.

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.

EasySocialFacebook login.

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 :).

EasySocialFacebook Login.

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.

Application GUI.
Authentication start.
Authentication Facebook.
Authentication facebook.
Authentication facebook.

8. Get user information from Facebook.

Get user information from Facebook.

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

Get user information from Facebook.

9. Post on Facebook.

Post message on facebook wall.

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

Post on Facebook.
Post on Facebook wall.

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.

Get image 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.

Get image 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.

Developer caller code.
Get image GUI.
Get image GUI.
Get image 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. :)