Steps for Facebook integration into your app

  1. Create your app on Facebook : http://www.facebook.com/developers/createapp.php
  2. Download Facebook SDK : http://developers.facebook.com/docs/guides/mobile
  3. Add Facebook SDK to your Android application
  4. Copy Application ID from Facebook
  5. Insert into your app Facebook controls as : LoginButton
  6. Insert extra code into your app
    1. /*
    2.  
    3.     <strong>public static final String APP_ID = "158312160885675";</strong>
    4.  
    5.     private LoginButton mLoginButton;
    6.     private Facebook mFacebook;
    7.     private AsyncFacebookRunner mAsyncRunner;
    8.  
    9.     /** Called when the activity is first created. */
    10.     @Override
    11.     public void onCreate(Bundle savedInstanceState) {
    12.         super.onCreate(savedInstanceState);
    13.  
    14.         setContentView(R.layout.main);
    15.         mLoginButton = (LoginButton) findViewById(R.id.login);
    16.  
    17.         mFacebook = new Facebook(APP_ID);
    18.         mAsyncRunner = new AsyncFacebookRunner(mFacebook);
    19.  
    20.         SessionStore.restore(mFacebook, this);
    21.         SessionEvents.addAuthListener(new SampleAuthListener());
    22.         SessionEvents.addLogoutListener(new SampleLogoutListener());
    23.         mLoginButton.init(this, mFacebook);
    24.     }
    25.  
    26.     <strong>@Override
    27.     protected void onActivityResult(int requestCode, int resultCode,
    28.                                     Intent data) {
    29.         mFacebook.authorizeCallback(requestCode, resultCode, data);
    30.     }
    31.  
    32.     public class SampleAuthListener implements AuthListener {
    33.  
    34.         public void onAuthSucceed() {
    35.                 Toast.makeText(getBaseContext(), "AuthSucceed!", Toast.LENGTH_SHORT).show();
    36.         }
    37.  
    38.         public void onAuthFail(String error) {
    39.                 Toast.makeText(getBaseContext(), "AuthFail : " + error, Toast.LENGTH_SHORT).show();
    40.         }
    41.     }
    42.  
    43.     public class SampleLogoutListener implements LogoutListener {
    44.         public void onLogoutBegin() {
    45.                 Toast.makeText(getBaseContext(), "LogoutBegin", Toast.LENGTH_SHORT).show();
    46.         }
    47.  
    48.         public void onLogoutFinish() {
    49.                 Toast.makeText(getBaseContext(), "LogoutFinish", Toast.LENGTH_SHORT).show();
    50.         }
    51.     }
    52.     }
    53.  
    54. }</strong>

  7. Generate hash key for singleSignOn
    keytool -exportcert -alias [alias] -keystore [keystore] | openssl sha1 -binary | openssl enc -a -e

    For Windows users : you must install Cygwin and run command in the cygwin shell or use a linux VM. The result from Windows command will not work

  8. Put your hash key on Facebook application page – mobile tab
  9. Run your app