Facebook API for Android

If you want to integrate your applicaiton with the Facebook, you have to create an Facebook app and enter information.

Facebook Application

After you have completed creating your new Facebook application, you should note your applcationID , because you will use it in your applicaiton to connect Facebook.


Download and install Facebook sdk

  1.  Goto github and download facebook sdk
  2. After Downloading Facebook  SDK open your android project and copy files from facebook folder to you application. ~\facebook-android-sdk-master\facebook-android-sdk-master\facebook\src\com\facebook\android
  3. Facebook sdk install to android project

    copy facebook sdk files to your projec

  4. After copying Facebook  files you can develop your applicaiton to connect facebook.
You have to add below permission to allow your applicaiton reach internet.

<uses-permission android:name="android.permission.INTERNET"/>

Open your main activity and write the code below in it.
Facebook connect android code

Facebook connect android codes

 

 

Let's try to run our application, what will happen ?

 

facebook misconfigured error

facebook misconfigured error

 

It gives an error, because  you didnt fill  the keyhash and Package name and classname fields in your Facebook application administration panel.

Filling Packagename and classname is easy, it comes from your manifest, you can refer to below url.

Facebook connect package-name , class-name, keyhash

Facebook connect package-name , class-name, keyhash

Facebook connect manifest file

Facebook connect manifest file

 

And now there are one empty fied named keyhas. Lets create our keyhas. There are an important point which should be paid  attention.  When you publish our application to google play, we will use our release.keystore so while creating our keyhash we will  use this key.

(To learn how to create keystore you can refer this url)

To create keyhash,

  1. Download openSSl from Code Extract it. create a folder- OpenSSL in C:/ and copy the extracted code here.
  2. detect debug.keystore file path. If u didn't find, then do a search in C:/ and use the Path in the command in next step.
  3. If we publish it we have to use release.keysore
  4. C:\Program Files (x86)\Java\jre6\bin\keytool -exportcert -alias androiddebugkey -keystore "C:\Documents and Settings\Administrator.android\debug.keystore" | "C:\OpenSSL\bin\openssl" sha1 -binary |"C:\OpenSSL\bin\openssl" base64 (this is for debug)
  5. C:\Program Files (x86)\Java\jre6\bin\keytool -exportcert -alias typeyourkeystorealias -keystore C:\path\release.keystore | C:\OpenSSL\bin\openssl sha1 -binary| C:\OpenSSL\bin\openssl  base64 (this is for release)
  6.  Now we can create our keyhash. (I used debug.keystore and execute it in java\bin you can do the same if you want)

 

Create hash key for facebook connect

Create hash key for facebook connect

 

Our keyhash is ready now, copy and past it to keyhash filed in facebook apps page.  (Dont try to write it , just right click to your cmd screen and click mark, then select that area where key is written, then pres enter.)

if you have got the same error, please generate your keyhash with release.keystore.

 

I hope it helps you to connect facebook from your android app.

 

 

 

 

 

 

 

Be Sociable, Share!

Category: Uncategorized Comment »


Leave a Reply



Back to top