This tutorial is about integrating facebook into your android application. I am going to explain various steps like generating your application signature, registering facebook application, downloading facebook sdk and other steps. Here is an official documentation of facebook integration.

Download Code

Generating App Signature for Facebook Settings

To create facebook android native app you need to provide your Android application signature in facebook app settings. You can generate your application signature (keyhash) using keytool that comes with java. But to generate signature you need openssl installed on your pc. If you don’t have one download openssl from here and set it in your system environment path.

Open your command prompt (CMD) and run the following command to generate your keyhash. While generating hashkey it should ask you password. Give password as android. If it don’t ask for password your keystore path is incorrect.

keytool -exportcert -alias androiddebugkey -keystore "<path-to-users-directory>\.android\debug.keystore" | openssl sha1 -binary | openssl base64

check the following command how i generated hashkey on my pc.

keytool -exportcert -alias androiddebugkey -keystore "C:\Users\Ravi\.android\debug.keystore" | openssl sha1 -binary | openssl base64
android facebook generating hash key app signature

Registering your Facebook Application

After generating your app signature successfully, register your facebook application by going to create new facebook application and fill out all the information needed. And select Native Android App and give your hashkey there which you generated previously using keytool.

android facebook register app

and note down your facebook App ID

android facebook app id

Creating Facebook Reference Project

Once you are done with registering your facebook application, you need to download facebook SDK and create a new reference project. This reference project will be used to compile your actual project.

1. Download facebook android SDK from git repositories.
(git clone git://

2. In your Eclipse goto File ⇒ Import ⇒ Existing Projects into Workspace and select the facebook project you downloaded from git repository.

android facebook import project

Creating Your Facebook Connect Project

1. Create new Project in your Eclipse IDE. File ⇒ New ⇒ Android Project and fill out all the details.

2. Now we need to add reference of this project to existing facebook project. Right Click on Project ⇒ Properties ⇒ android ⇒ Click on Add button ⇒ select your facebook project ⇒ Click Apply.

android facebook adding reference project
android facebook adding reference project
android facebook adding reference project

Now our project setup is done. We can start coding our facebook application.

3. Open your AndroidManifest.xml file add network connect permission in order to connect to internet.

<uses-permission android:name="android.permission.INTERNET"/>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

        android:label="@string/app_name" >
            android:name=".AndroidFacebookConnectActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

    <!-- Connect to Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET"/>


4. Open Your Main Activity Class and initialize all the variables needed.

public class AndroidFacebookConnectActivity extends Activity {

	// Your Facebook APP ID
	private static String APP_ID = "308180782571605"; // Replace your App ID here

	// Instance of Facebook Class
	private Facebook facebook;
	private AsyncFacebookRunner mAsyncRunner;
	String FILENAME = "AndroidSSO_data";
	private SharedPreferences mPrefs;

	public void onCreate(Bundle savedInstanceState) {

		facebook = new Facebook(APP_ID);
		mAsyncRunner = new AsyncFacebookRunner(facebook);

5. I created a simple interface which contains button to login, post to wall, show access tokens and logout for testing purpose.

Login to Facebook Account

I used a button to login into facebook account. In your activity write a click event for Login button click. Inside click event declare a function named loginToFacebook();

Login button click event

btnFbLogin.setOnClickListener(new View.OnClickListener() {
	public void onClick(View v) {

and function body for loginToFacebook() function is:

	public void loginToFacebook() {
		mPrefs = getPreferences(MODE_PRIVATE);
		String access_token = mPrefs.getString("access_token", null);
		long expires = mPrefs.getLong("access_expires", 0);

		if (access_token != null) {

		if (expires != 0) {

		if (!facebook.isSessionValid()) {
					new String[] { "email", "publish_stream" },
					new DialogListener() {

						public void onCancel() {
							// Function to handle cancel event

						public void onComplete(Bundle values) {
							// Function to handle complete event
							// Edit Preferences and update facebook acess_token
							SharedPreferences.Editor editor = mPrefs.edit();

						public void onError(DialogError error) {
							// Function to handle error


						public void onFacebookError(FacebookError fberror) {
							// Function to handle Facebook errors


android facebook login

Posting Message to Facebook Wall

write a click event for post to wall button and inside click event write a function named postToWall()

btnPostToWall.setOnClickListener(new View.OnClickListener() {
	public void onClick(View v) {

and function body for postToWall() function is:

	public void postToWall() {
		// post on user's wall.
		facebook.dialog(this, "feed", new DialogListener() {

			public void onFacebookError(FacebookError e) {

			public void onError(DialogError e) {

			public void onComplete(Bundle values) {

			public void onCancel() {

android facebook posting to wall
android facebook posting to wall test

Getting Profile Information from Facebook

To get profile information we need to make an api request to facebook graph API. Following is a function that will make an api request to facebook profile graph api and will get profile information from facebook.

	public void getProfileInformation() {
		mAsyncRunner.request("me", new RequestListener() {
			public void onComplete(String response, Object state) {
				Log.d("Profile", response);
				String json = response;
				try {
					JSONObject profile = new JSONObject(json);
					// getting name of the user
					String name = profile.getString("name");
					// getting email of the user
					String email = profile.getString("email");

					runOnUiThread(new Runnable() {

						public void run() {
							Toast.makeText(getApplicationContext(), "Name: " + name + "\nEmail: " + email, Toast.LENGTH_LONG).show();


				} catch (JSONException e) {

			public void onIOException(IOException e, Object state) {

			public void onFileNotFoundException(FileNotFoundException e,
					Object state) {

			public void onMalformedURLException(MalformedURLException e,
					Object state) {

			public void onFacebookError(FacebookError e, Object state) {

The above function will get json data from facebook. You need to parse the json in order to get individual profile data. If you are not aware of json parsing look at this article. Android JSON Parsing Tutorial.

The sample profile json from facebook will be like this

   "id": "1464730016",
   "name": "Ravi Tamada",
   "first_name": "Ravi",
   "last_name": "Tamada",
   "link": "",
   "username": "ravi8x",
   "birthday": "12/22/1988",
   "hometown": {
      "id": "112158005464147",
      "name": "Baruva"
   "location": {
      "id": "102186159822587",
      "name": "Chennai, Tamil Nadu"
   "bio": "Author:\r\nCo-author:",
   "work": [
         "employer": {
            "id": "179366562092719",
            "name": "ByteAlly"
         "location": {
            "id": "102186159822587",
            "name": "Chennai, Tamil Nadu"
         "position": {
            "id": "124917314217511",
            "name": "Product Head"
   "favorite_athletes": [
         "id": "18620649907",
         "name": "Virat Kohli"
   "education": [
         "school": {
            "id": "131587206873093",
            "name": "Raghu Engineering College (REC)"
         "degree": {
            "id": "140065339390579",
            "name": "B.Tech"
         "year": {
            "id": "142963519060927",
            "name": "2010"
         "type": "Graduate School",
         "classes": [
               "id": "192259410803415",
               "name": "2010",
               "with": [
                     "id": "584960408",
                     "name": "Santosh Patnaik"
               "from": {
                  "id": "584960408",
                  "name": "Santosh Patnaik"
   "gender": "male",
   "relationship_status": "Single",
   "website": "\\\",
   "timezone": 5.5,
   "locale": "en_US",
   "languages": [
         "id": "106059522759137",
         "name": "English"
         "id": "107617475934611",
         "name": "Telugu"
         "id": "112969428713061",
         "name": "Hindi"
         "id": "343306413260",
         "name": "Tamil"
   "verified": true,
   "updated_time": "2012-03-02T17:04:18+0000"

Extending facebook Permissions

If you want user’s other information like checkins, friends list etc., you need to extend facebook permissions while logging in user. Check list of facebook permissions

facebook.authorize(this, new String[] { "email", "publish_checkins", "publish_stream" },

      new DialogListener() {
           public void onComplete(Bundle values) {}

           public void onFacebookError(FacebookError error) {}

           public void onError(DialogError e) {}

           public void onCancel() {}

Getting Access Token

Sometimes you might needed users access token for future purpose usage. Following code will give you currently logged in user access token.

String access_token = facebook.getAccessToken();

Logout from your app

When user want to stop using facebook for your app, you can provide logout method to clear app state and invalidate access token. So further you can’t make request to facebook from your app.

	public void logoutFromFacebook() {
		mAsyncRunner.logout(this, new RequestListener() {
			public void onComplete(String response, Object state) {
				Log.d("Logout from Facebook", response);
				if (Boolean.parseBoolean(response) == true) {
					// User successfully Logged out

			public void onIOException(IOException e, Object state) {

			public void onFileNotFoundException(FileNotFoundException e,
					Object state) {

			public void onMalformedURLException(MalformedURLException e,
					Object state) {

			public void onFacebookError(FacebookError e, Object state) {
This image is for thumbnail purpose
android facebook connect
Hi there! I am Founder at androidhive and programming enthusiast. My skills includes Android, iOS, PHP, Ruby on Rails and lot more. If you have any idea that you would want me to develop? Let’s talk:

    I Tried but after click on Button it is not loading facebook just loading image is continuously displayed, can any one sugges what is wrong with me?

  • Mohsin Muhammad Aaheer

    I have completely followed this tutorial, got hash key, created facebook app,
    got fb key and put it in your app.
    but when I run your app project in your download zip, after running it shows first screen, button on screen to login facebook, when I press that button the app crashed???
    please help?
    why don’t it connects with my fb app and post status their as your are posing in tutorial?

  • sangu

    plz help me any one..
    how to get the list of active friends,

    and the list of friends of selected friend..?

  • First I would like to appreciate your awesome work. Now coming to my problem I m getting this response while getting the profile. {“error”:{“message”:”An active access token must be used to query information about the current user.”,”type”:”OAuthException”,”code”:2500}} . what should I do. I am following your tutorial step by step. I m sure that I have not missed any of step described. Also please tell me the new classes. Some of them are deprecated now. Thanks

  • Praveen Mylavarapu

    Hi, I am a beginner. Should we upload the app in google play or on fb ??

  • prashant

    me also getting the same error..struck here

  • Oliver Jordan

    Hi ravi thank you for the tutorial, it works fine on me. Now after login i want to make my app displays the list of my groups on facebook. Is it possible? if yes, would you show me the way to do that? pleaseee 🙂

    thanks in advance

  • when im logouting it gives exception

  • Dinesh Bagvan

    thats very good ….

  • Stefano Occhi

    hi! this is the best tutorial, but i have a problem! I could do the first login with my facebook account, but, now, on the others login i receive an error from facebook page on the app: “Invalid android_key parameter. The key Vp1b———G4TI does not match any allowed key. Configure your app key hashes at http://developers.facebook……/apps/139—– “. I don’t understand this error, because the key cited is not my hash key and why the first login went well?? i think the app is configured well!

    • Stefano Occhi


  • hadson

    TNX man… uffff

  • seenu

    can publish an article about facebook login with mysql?

  • Jonathan Besinan

    Hi Sir, thanks for the tutorial. It’s really great! is it possible to connect facebook chat in android application?

  • tushar

    There is phrase , for you in my dictionary …. you are helping millions of people in this world , thanks !

  • KT

    How can i post msg to fb wall when a user clicks on a button ?

  • Faiza Saleem

    gr8 work.. keep it up

  • Bhavin Doshi

    Good tutorail !

  • Mit Bhatt

    Thanks…. 🙂

  • Mukesh Garg

    Thanks for such a gr8 tutorial . really it was very helpful. could u post a tutorial for Facebook Like through Android ?

    • Goutam Kundu

      The same mukesh from palle tech ………..goutam here look like facebook work is going on

  • nitin

    thanq…it is very usefull…..

  • Erwandy 林棋良

    Thank u very much for the code…

    But, I have a question.
    Actually, how is the way to logout?

    I hv tried the logout code above, it’s worked. But, when I clicked for my login button, it always runs successfully on getting access as a logged-in user.
    so, I think it has no differences between I log out and I log in…

    Thanks before…
    Please kindly explain more detail for the way of logout session.
    Thank u so much…

  • Faraz

    when i first time logs in then it shows Error and a okay button when click on okay button it redirects to login with facebook button.

  • sanjay sawan

    can u tell me how can make a application which support the voice password protected…if u have any suggestion regarding this plz inform me at

  • Kavi ManiKumar

    Good tutorial…….Thankq…..

  • Arpit

    When i click on login with facebook button, it shows a dialog box then came back to same screen

    • Felipe

      same problem

      • Felipe

        The problem was that the facebook app was set to sandbox mode, so only developer accounts could get access token from app’s ID. It works to me.

  • Rahul Arora

    How can we get Friends list and their B’day list using this tutorial??? plz help me…

  • srikanth gutti

    trying this FB example with new FB SDK 3.0.2 getting error here i am placing the log to fix this
    08-16 01:00:41.652: E/AndroidRuntime(4420): FATAL EXCEPTION: main
    08-16 01:00:41.652: E/AndroidRuntime(4420): java.lang.NoClassDefFoundError:
    08-16 01:00:41.652: E/AndroidRuntime(4420): at com.facebook.androidhive.AndroidFacebookConnectActivity.(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at java.lang.Class.newInstanceImpl(Native Method)
    08-16 01:00:41.652: E/AndroidRuntime(4420): at java.lang.Class.newInstance(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at
    08-16 01:00:41.652: E/AndroidRuntime(4420): at
    08-16 01:00:41.652: E/AndroidRuntime(4420): at
    08-16 01:00:41.652: E/AndroidRuntime(4420): at$1500(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at$H.handleMessage(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at android.os.Handler.dispatchMessage(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at android.os.Looper.loop(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at
    08-16 01:00:41.652: E/AndroidRuntime(4420): at java.lang.reflect.Method.invokeNative(Native Method)
    08-16 01:00:41.652: E/AndroidRuntime(4420): at java.lang.reflect.Method.invoke(
    08-16 01:00:41.652: E/AndroidRuntime(4420): at$
    08-16 01:00:41.652: E/AndroidRuntime(4420): at
    08-16 01:00:41.652: E/AndroidRuntime(4420): at dalvik.system.NativeStart.main(Native Method)

  • ugur

    very thanks useful tutorial. i want a question. my language Turkish. But i’m get string english. example: i get string gender famale, but i convert my language. how i do?

  • bobby

    when I try to this its showing me error of some link

  • rado

    Please how can I change login fragment to fullscreen?

  • Trollzito

    ok nice!

  • Mahivardhan Singh

    Ravi Tamada is my guru(Teacher) of android…thnks ravi

  • Guru Prasad

    Hi Sir when i ma going to integret to my app i am getting SharedPreferences error..bcz u are retrving access token from mpref before its creating ..pls let me knw as soon as possible…pls give me reply to my email ……………

  • GaneshKumar B

    Great tutorial..I need to get my own mobile number while login.How can it be..?

  • Sathish

    HI this is very nice tutorial… I have one doubt, How to get “hometown”, “location” and etc… I am not getting the response for “hometown”, “location” and etc…

    • If user filled these details in their profile, then only you will get the response. Otherwise those values won’t be there in the response.

      • Sathish

        Thanks. Now I got the “hometown”, “location”. My facebook account has user image, mobile number, birthday and address. I am not getting the “address”, “birthday” and “mobile number” and “user image”.

  • mangesh kaduskar

    I already have Facebook android app in my mobile. And when i try to use my application using Facebook log in integration with this example it doesn’t give me any response.
    Please help me.

  • suresh kumar

    Hi the code works fine in emulator but fails in real device.

  • shivaprakash

    Its working fine for me. One thing I want to know how o post image on wall, instead of text I want to post image.

  • Guest

    Hi my hash key is not matched error in login facebook.on SOS signin process.kindly leave reply

  • Harshpreet Singh

    cant install openssl…someone plz help..

    • Catcha Freeman

      have you succeeded? i have a solution

  • Relin Jose P.M.™
  • manish

    Download openSSL->Install it->it would usually install in C:OpenSSL

    then open cmd and type

    cd../../Program Files (enter)

    java (enter)

    dir (enter)

    cd jdk1.6.0_17 (varies with jdk versions)
    to check jdk version go to C:/program files/java/jdk_version

    cd bin (enter)

    keytool -exportcert -alias androiddebugkey -keystore C:UsersShalini.androiddebug.keystore | “C:OpenSSLbinopenssl sha1 -binary | “C:OpenSSLbinopenssl base64 (enter)

  • Marcos Henrique da Silva

    thanks for this great and easy tutorial!

  • KD

    thanks For this great and easy tutorial ~!=
    But how can , send Post message from Programming …

  • Vova

    Thanks! It works! However many methods are deprecated. How to fix hat?

  • anaya

    after laoding fb login page does not open…please help me…..

  • AirJordan

    this article should be considered obsolete, because Facebook has obsoleted “facebook” class…. 🙁

  • ShahNawaz Khan

    This really has become obsolete. Started using SocialAuth for android but it lacks proper documentation 🙁 please help!!!

  • Tahir Mahmood

    not working … no error in code but still not opening … 🙁

    • This is deprecated I think. Please follow the tutorial on facebook official doc.

      I need to update this tutorial yet

  • ShahNawaz Khan

    Please provide a tutorial to integrate SocialAuth!
    1.Connect to provider
    2.Save Access Tokens
    3.Update Status

    I just cannot find the documentation, You’re my last resort plz help!

  • christowly

    I just download all code and import it. There’s to many error on it.
    What’s wrong with it ?

  • Jagdeep Singh

    What if we want to add inbuilt text to be post via facebook post. Like score or some data generated at run time.??

  • Mubashir

    Logout function not work 🙁 ………..Plz help

  • sarita gandhi

    How to upload photos from gallery to facebook?

  • shiva


  • shiva

    how to upload images and videos from gallery to facebook ?

  • Vasudev Vyas

    how can we perform this steps in Android Studio?

  • “C:UsersRavi.androiddebug.keystore” What does this path mean? thanks.

    by the way im using Eclipse

    • Jagdeep

      That’s the path of the keystore that you have replace with your keystore Path.

  • Ujjwal Bose

    hey can you please tell me how to fetch the list of friends who are online..???

  • Ujjwal Bose

    and one thing more when i use the latest facebook sdk 3.6.0 the method to log-in and other gets Deprecated…can you help me with this..??

  • Aditya Delightful Guy

    how can i get birthday reminder notifications in my app after integrating facebook friends birthday ???Please can you heip me ??

  • Aung Tun Kyaw

    I can’t get birthday from json Array. There’s no birthday in json array.

  • How do I set the openssl in my system environment path? I’m using Windows 7. I’m having this error message: “openssl is not recognized as an internal or external command”.

    • Ashish Tiwari

      download openssle and extract on your c drive. then open that forlder. You will find an exe named openssl. give path of this file in command prompt where you are giving only “openssl”

  • Amit Gahlot

    not working

  • Amit Gahlot

    can u tell me how to create number puzzle application of 4×4

  • maddy

    Please updade your code for integrating facebook sdk 3 or higher

  • Najeeb Idrees

    My app works fine on emulator , or on those devices where facebook app is not pre installed. When i run this app on those devices where facebook app is pre installed i got error and cannot login.

  • Maheswaran Murugan

    Hi I’m Maheswaran. This code working first time only, when I click the login button second time it’s not working. I don’t have fb api in my emulator. Please help me to solve my problem.

  • rohan

    Nice tutorial I have a question… How to send my facebook wall posts through my facebook app installed by other users…. I mean how to get my data to many users who have my app which is integrated with facebook. I have a community on facebook & want my users to receive notifications of it . I will just update any image or text over that community & it must be availabe to all my friends having myApp with notificaion

  • Maheswaran Murugan

    Hi please help me any body to implement facebook and twitter login in my application.

  • geeta

    sir, this was very useful. but i would like to know how to display friend lists and share a post to their wall. pls help me 🙁 very urgent..

  • Ras

    How do i setup the SSL? Just unzipped it in “c:openssl” and added “;C:opensslbin” to path variable underneath System variable. do i need to do anything else? or how to check it?

  • Vaishali Bhujbal

    i’m getting warning {“error”:{“message”:”An active access token must be used to query information about the current user.”,”type”:”OAuthException”,”code”:2500}} while getting user info.How to sovle it

    • satishpoul

      Access token you are using is for corresponding operation is not valid or old. please use latest or new access token.

  • AMI

    hi sir i have succeed facebook intregration it work fine, but i have a problem when facebook app is present in a device this example don’t work and if i unstall facebook app this code work fine. i don’t understand that is problem.

    • Piyush

      I am also facing the same problem…. can you just share your ideas..

  • Pranav Mahajan

    On post I want a default message in the dialog box like “Hello World”.
    Has anybody done this or can suggest something??

  • Akash

    The logout function aint working bro can u help wid that…..

  • Dipesh

    How to Generat App Signature in Linux Centos . ??

  • Vipul

    Help Please !!!!!

    I want to get the user Education data ie name of college he or she went to ? I tried my level best .Please help me figure out this .

    • vo

      Read json file which is in key-value pair..

  • asif

    how to create hash key for ubuntu

    • Ziyed Rebhi

      keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

      • Eric

        Works for Mac as well! Thanks!

  • Nasif Ahmed

    Thanks for your great tutorial. Many guys like me asking you a question. How to post a default massage? Can you please add this function to your code or show the way?

  • jaga

    God bless you

  • vishal gadhiya

    how to obtain my facebook friends

  • Sreenu Krishnamaneni

    All the above process is deprecated. Please add latest otherwise delete the post.

  • Tejashree Kulkarni


  • Senthilnathan

    Nice… If the facebook application is already installed and logined at that time how to it will work.

  • Saurav Bhatia

    no peer certifiacte exception……whats the solution for this??

  • hicham abdedaime

    help me please how to get image.?? thanks

  • Khairunisa Aina

    how if I want to post at facebook group not our wall..

  • Mughilavan


  • Mughilavan


  • Chuột Tí

    Hi Ravi! You can help me? How to get new feed Facebook? I readed the document in dev.facebook but i don’t understand. You can give me one example detail?

  • Hi can you update this tutorial for Facebook SDK 3.0 , This tutorial won’t work with the latest version.

    • Adam Kesegić

      Yeah Ravi, this would be pretty useful I agree with Midhun. Facebook SDK 3.0 (and Graph API v2.1) is having a few changes, some functions are deprecated and others are used (e.g. Facebook = Session, isSessionValid = isOpened/isClosed, etc.), feed structure seems a bit changed, and also different access token handling too – at least I think so. Would it be problem to update (or make a new tutorial) on this?? Thanks Ravi, I really appreciate it!

  • Chu Việt Hưng

    How to get image show album user as gridview?

  • Myagentcalljournal Journal

    Hi, how can i post a message on facebook page

  • bidhu

    Hello ,This application works only once . On second time installation its giving error.Please help me in this .


    It works with activity, but when I use same piece of code with fragment activity, it doesn’t work. I need help asap.

  • Bincy

    When i run this i got an error , App not setup.The developer of this app have not setup this app properly for facebook login. Can you help me …please…..

  • Bincy

    I followed all steps described in this tutorial…When I run this app i got an error “The application has disabled OAuth client flow” can anyone help me…please…..

  • Eps Epages

    Hi..I am getting exception just after getting accesstoken,It says Failure delivering result ResultInfo{who=null, request=32665, result=-1, data=Intent { (has extras) }},Please help me

  • akhil

    thanx for the tutorial. Everything is working fine but when i close my app and restart it again the fb login doesn’t work. Uninstalling the app and reinstalling makes the problem go away but only for the first time login. has the “access token” and “access-expires” got to do anything with that, please help

  • Vivek

    Logout function not working .. Getting No Method Found error. Can you please assist on this. Thanks.

  • Felipe Roche

    NICE!!!! thanks U!!! I download your code, in ProyectPropertiesAndroid update Facebook SDK then build proyect and Vuala!

  • Ritesh Ojha

    Thnx for this helpful project Ravi. Can you please help me post/share a specific text every time using posttowall method. I dnt wana write text however wants to share a specific info everytime. please help.

  • rocko

    Copy-pasted from stackoverflow.

    go to eclipse— window— preferences— Android—Build—default debug keystore— from here get the path to keystore.

    The correct way to create a hash key

    Please follow the following steps.

    Here are the steps:

    Download OpenSSL from Google Code

    Extract it. Create a folder- OpenSSL in C:/ and copy the extracted code here.

    detect the debug.keystore file path. If you don’t find it, then do a search in C:/ and use the path in the command in next step.

    detect your keytool.exe path and go to that dir/ in a command prompt and run this command (in one line):

    $ keytool -exportcert -alias androiddebugkey -keystore
    “C:Documents and SettingsAdministrator.androiddebug.keystore” |
    “C:OpenSSLbinopenssl” sha1 -binary |”C:OpenSSLbinopenssl” base64

    it will ask for a password. Put “android”, that’s all. You will get a key-hash.

    • Ameen Maheen

      thanks man it really helped

    • Uttami Singh

      thanks frnd saved my day. none helped me except yours.

  • vimlesh

    Hi Ravi,
    After signing apk login getting failed

  • Guest

    need help on the cmd line codes when i set path of java it shows openssl not recognised
    and vice versa,wat to do ? i installed both java and oppen ssl lite

  • saurabh

    logout dosen’t work , give me a correct code … can any one help me..

  • Ankit

    Hi Ravi,

    It doesn’t give me the user email address.

  • Mayank Langalia

    hi friends,
    anybody have you any idea
    how to get friends list (name, image)
    if you have any idea then let me know ..

  • Hi,
    I am an android developer, I want to know how to get private fb profile information.

  • AP

    how do i follow this steps in ubuntu(linux) for integrating in my app

  • Ramesh kannan

    logoutfromfacebook( ) method is not working ………..when i login with enter all credentials after logout then automatically logged in

    • Dilip Birajadar

      Yes Logout Method is not working something is wrong there

  • Guest

    I don’t understand, when I try to post on my wall, I am getting these errors, the others options are fine
    01-04 01:54:27.418: E/test(14752): Exception

    01-04 01:54:27.548: E/AndroidRuntime(14752): FATAL EXCEPTION: main

    01-04 01:54:27.548: E/AndroidRuntime(14752): java.lang.NoClassDefFoundError:$string

    01-04 01:54:27.548: E/AndroidRuntime(14752): at com.facebook.widget.WebDialog.onCreate(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at com.mearimmapas.slidingmenu.AndroidFacebookConnectActivity.postToWall(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at com.mearimmapas.slidingmenu.AndroidFacebookConnectActivity$3.onClick(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at android.view.View.performClick(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at android.view.View$

    01-04 01:54:27.548: E/AndroidRuntime(14752): at android.os.Handler.handleCallback(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at android.os.Handler.dispatchMessage(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at android.os.Looper.loop(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at java.lang.reflect.Method.invokeNative(Native Method)

    01-04 01:54:27.548: E/AndroidRuntime(14752): at java.lang.reflect.Method.invoke(

    01-04 01:54:27.548: E/AndroidRuntime(14752): at$

    01-04 01:54:27.548: E/AndroidRuntime(14752): at

    01-04 01:54:27.548: E/AndroidRuntime(14752): at dalvik.system.NativeStart.main(Native Method)

  • karathb

    an update would be great 🙂

  • Bhanwar Gupta

    Hello, An update using the latest API version would be of great help. This works, but code is deprecated. Thank You

  • Parvathi Krishnan

    Hey ravi,I want get like For my App when the user login,and the User should be able to unlike it also,
    If you have code means could please help me with that


    Hello, Once I login how can I logout from facebook.

    Can you please update with new API

  • Ashish Tikarye

    App have not set up this app properly for Facebook login…getting this error…help plz

  • Deepak Ror Maratha

    hello Ravi ,
    your Site is awsome
    but not updated blogs( API ).
    Here Is blog about facebook since 2012.
    Please update blog with facebook 4.v and others blog.

  • Swapnil Ramtekkar

    hello ,
    how can i access the profile image
    thank you..

  • Sara Raza

    if any one facing in the login issue and go on left panel of app in website and press app detail and then press Configure App Center Permissions and set permission .. in code that is remove second element of the Arrr this new String[] { “email”, “publish_stream” } replace as new String[] { “email”} and then run app should be working for me……

  • Renitto Jose

    facebook login not working any more due to their api change and new permission settings . anyway to resolve this ??

    • Kaveesh Kanwal

      read the facebook developer’s documentation.

  • jatin

    hi Ravi Sir i can’t post the data how can i post image give example plz

  • Eduard Albu

    In my app I want to show the latest post of a Facebook page and users to be able to leave and read comments to/from that post. Please help, how can I realize this?

  • sanjay thakur

    Thank you Ravi your code always work for me..:)

  • android

    Hi,my application has an form login (with an editext for email and an editext for password)….How can i login with facebook with this parameters? I woudln’t show the facebook dialog for login…
    Thank you!!

  • good………….. please send me how to access friend list facebook

  • Mani kandan

    Code is working fine.. thank ravi.. But i didnt get the value for email in JSON while getting profile information. I got only two values fb ID and name from response.. How can i get email and date of birth????

    • darshan

      i also have same problem. please help me if you have got the solution.

    • Hoàng Dũng Phi

      you should get permission and change method how to get token

  • Kshitij Mandloi

    my facebook sdk comes with error and i also cant find it to be added in reference

    • Parth Anjaria

      Even i am getting errors in my sdk
      please help me
      followed few steps online.. but it isnt helping

  • Anshul Tyagi

    Ravi update some code with new SDK versions too with new functions like post a link on friend’s timeline.

  • Viany

    download link not working..!!:-X

  • kamal

    bro how to add permissions for getting email,phone number,birthday date,age,etc,…

  • rupesh gohil

    Even i am getting errors in my sdk Android library projects cannot be launched.
    how can sole it please help me

  • Åmol Çhavhan

    Plz update your facebook connect tutorial with latest facebook sdk . this is deprecated now

  • shiva

    when i click on get profile button it is not displaying any toast mesaage.Ravi can you explain one line of code i.e Resonse attribute in onComplete method.If i want to display the response ,getting only name and id…So what about email buddy.

  • Niranjan Reddy

    Here iam not getting email , it showing no value of email what is the solution for this ?

  • Dilip Birajadar

    I am also not able to logout.

  • Chakradhar

    Hi, I am facing issue in adding the facebook sdk as library to my project. When i click on the properties it is not even showing the facebook sdk in the select library window. I have already imported sdk to my workspace. Please help me.

  • Tharindu Dhanushka

    when I run the app give this message “App not setup: this app is still in development mode, and you don’t have access to it. switch to registered test user or ask an app admin for permissions” why it came

  • okky agung

    Thanks Ravi . but Logout button Error. can you fix that ?


    Code is working fine.. thank ravi.. But i didnt get the value for email in JSON while getting profile information. I got only two values fb ID and name from response.. How can i get email and date of birth????

    • Anand Mohan

      Hi Rajendra,
      I am faced same problem while integrating Facebook to my application. Instead of publish_stream you should use publish_actions. Please use below code to get email,name,gender..etc

      Note: before use getprofileinformation method use must add below code in oncreate

      if (android.os.Build.VERSION.SDK_INT > 9)
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

      public void getProfileInformation()
      Bundle parameters = new Bundle();
      String mAccessToken = facebook.getAccessToken();
      String parms =”gender”+”,”+”birthday”+”,”+”first_name”+”,”+”email”;
      parameters.putString(“format”, “json”);
      String url = “”;
      JSONObject obj;
      try {
      String response = null;
      try {
      response = Util.openUrl(url, “GET”, parameters);
      JsonObject jsonObject = new JsonParser().parse(response).getAsJsonObject();
      String email = jsonObject.get(“email”).getAsString();
      String first_name = jsonObject.get(“first_name”).getAsString();
      String gender = jsonObject.get(“gender”).getAsString();
      Log.d(“email”, “email****************”+email);
      Log.d(“first_name”, “first_name****************”+first_name);
      Log.d(“gender”, “gender****************”+gender);
      } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      } catch (IOException e) {
      // TODO Auto-generated catch block
      obj = Util.parseJson(response);
      Log.i(“json Response”, obj.toString());
      JSONArray array = obj.optJSONArray(“data”);
      } catch (JSONException e) {
      // TODO Auto-generated catch block
      } catch (FacebookError e) {
      // TODO Auto-generated catch block

      • Sabin B S

        hii Ananad Mohan.. how to get fb profilepicture from this parsing? can you please help me?

  • Anand Mohan

    Nice Tuts Ravi

  • ÃñüshKA Verma

    Sir How to get Friend list using graph api..i wanted only the names not the paging details


    Can you tell me the way to send app invites to facebook contacts?

  • Dhanya

    Ravi..I have use android studio 1.5.1 and i used the facebook sdk 4.0.0.I cant integrate this code to my studio,the “Facebook” imports are not working.I think this code only works in that so?
    could u give me a proper solution?

    • Prashant Singh Verma

      Yes, may be you should try with the latest FB sdk + Login Manager class to integrate fb login.

  • Shaleen Jain

    Hi Ravi! I am trying to implement app invites via facebook in my android app and I’m really not able to figure out how to do it. Could you please make a tutorial for that?

  • Shaleen Jain

    Hi Ravi! I am trying to implement app invites via facebook in my android app and I’m really not able to figure out how to do it. Could you please make a tutorial for that?

  • Sarafaraz Babi

    how to send friends app request to add friends in to my app

  • Android Developer

    hello ravi past 2- years i am using your code in development . Thanks for this currently i am using that facebook code but i have facing the error org.json.JSONException: No value for email

    • Muhammad Afzal

      the account you are trying to login does’t want to share his/her email, this exception only occur in this case

  • harsha

    when i submit key hash generated from keytool from my system and integrated on facebook developer site after run the app showing keyhash not match wit….

  • Tiến Phạm Minh

    i am wondering if i have a login screen, i using facebook account to connect, if user login success then how can i get user’s info to mve to main screen? do i have to use intent to put extra? please help me 😀

  • Neeraj Shah

    How to store user information like name ,email id to database via FB login ?

  • Agus Suhariyanto

    how logout from facebook. this code not work.

    how to clear app cache for facebook session cache delete

  • Abhishek Abhi

    hi can we get username, email, gender, phone number through facebook based user login. is it possible.

  • {
    “id”: “1464730016”,
    “name”: “Ravi Tamada”,
    “first_name”: “Ravi”,
    “last_name”: “Tamada”,
    “link”: “”,
    “username”: “ravi8x”,
    “birthday”: “12/22/1988”,
    “hometown”: {
    “id”: “112158005464147”,
    “name”: “Baruva”
    “location”: {
    “id”: “102186159822587”,
    “name”: “Chennai, Tamil Nadu”
    “bio”: “Author: http://www.androidhive.infornCo-author:“,
    “work”: [
    “employer”: {
    “id”: “179366562092719”,
    “name”: “ByteAlly”
    “location”: {
    “id”: “102186159822587”,
    “name”: “Chennai, Tamil Nadu”
    “position”: {
    “id”: “124917314217511”,
    “name”: “Product Head”
    “favorite_athletes”: [
    “id”: “18620649907”,
    “name”: “Virat Kohli”
    “education”: [
    “school”: {
    “id”: “131587206873093”,
    “name”: “Raghu Engineering College (REC)”
    “degree”: {
    “id”: “140065339390579”,
    “name”: “B.Tech”
    “year”: {
    “id”: “142963519060927”,
    “name”: “2010”
    “type”: “Graduate School”,
    “classes”: [
    “id”: “192259410803415”,
    “name”: “2010”,
    “with”: [
    “id”: “584960408”,
    “name”: “Santosh Patnaik”
    “from”: {
    “id”: “584960408”,
    “name”: “Santosh Patnaik”
    “gender”: “male”,
    “relationship_status”: “Single”,
    “website”: “”,
    “timezone”: 5.5,
    “locale”: “en_US”,
    “languages”: [
    “id”: “106059522759137”,
    “name”: “English”
    “id”: “107617475934611”,
    “name”: “Telugu”
    “id”: “112969428713061”,
    “name”: “Hindi”
    “id”: “343306413260”,
    “name”: “Tamil”
    “verified”: true,
    “updated_time”: “2012-03-02T17:04:18+0000”

  • I am trying to generate hash key but it is showing a very big key as attached in screenshot here ,

    in that where is the hash key??

    I tried by opening cmd from this path too:

    > C:Program FilesJavajdk1.8.0_112bin

    bu still same issue..

  • বিপিয়া টিউটোর

    Need Android Studio Project. This is old system. And Download link is appear like broken or server down. Please resolve or give me idea about integrate it to android studio. Thanks.

  • saad

    nice tuts sir

  • Gowtham Nimmagadda

    My app has completed the facebook login.

    How to integrate Facebook Page with android . Does any one have any reference for that ?

  • amol

    Hi! Sir Can i get User Mobile no ?

  • ferjaoui wissal

    Hi, I have this error “Erreur de connexion:Une erreur s’est produite lors de la connexion à cette application.Veuillez réessayer plus tard.” can you help me please

  • Shivani Verma

    hello sir i have create the login integration but i want the user profile picture in navigation header but i am not able to get it there can you please help me

    • Are you able to get the user profile image url from Facebook?

  • MrBrown

    Hi, I want to post an Image with caption to FB WorkPlace Group. Is it possible ? How to do it? Any suggestion?

    • Check the FB official docs and their SDK.

  • ankur upadhyay

    how can we post message on facebook please reply fast

  • Tushar Nigam

    Is there are any way to follow my fb page from my app.

  • Vanshika Shah

    Could u pls share how to integrate Custom app events for android application using facebook sdk ?hOW CAN I TRACK CUSTOM APP EVENETS FROM FACEBOOK DASHBOARD Pls.