First ensure that you have Basic PhoneGap application running on your android. Check this tutorial if needed. Official tutorial is not so good but might help you out if Phonegap Facebook tutorial here fails. For additional information go to https://github.com/davejohnson/phonegap-plugin-facebook-connect/blob/master/README.md.
- Download PhoneGap Facebook plugin from https://github.com/davejohnson/phonegap-plugin-facebook-connect/tree/master/www
- Move cdv-plugin-fb-connect.js into your android phonegap webroot assets/www
- Include it in index.html <script type=”text/javascript” charset=”utf-8″ src=”cdv-plugin-fb-connect.js”></script>
- Add <plugin name=”org.apache.cordova.facebook.Connect” value=”org.apache.cordova.facebook.ConnectPlugin” /> into res/xml/plugins.xml
- Download facebook_js_sdk.js from https://github.com/davejohnson/phonegap-plugin-facebook-connect/tree/master/lib
- Create package org.apache.cordova.facebook and class ConnectPlugin.java. Copy contents of this file into it https://github.com/davejohnson/phonegap-plugin-facebook-connect/blob/master/native/android/src/org/apache/cordova/facebook/ConnectPlugin.java
- Add package com.facebook.android and .java files from https://github.com/facebook/facebook-android-sdk/tree/master/facebook/src to your java source. This enables ConnectPlugin.java to compile.
- Add import to com.package.your.R; or whatever is your android package so that your R.java will be imported to FbDialog.java.
- Merge facebook icons from https://github.com/facebook/facebook-android-sdk/tree/master/facebook/res to your project res folder. This enables Facebook SDK sources to compile. Espacially is needed this image https://github.com/facebook/facebook-android-sdk/blob/master/facebook/res/drawable/close.png
- Verify the facebook using javascript methods in here. https://github.com/davejohnson/phonegap-plugin-facebook-connect/blob/master/example/www/index.html
- Dont forget to register you facebook android app, add your APP id to the init method and register your app signing key in facebook. About creating signing key hash look into https://developers.facebook.com/docs/mobile/android/build/#sig
Download the Full Eclipse project sources here: FacebookTest
In case of any issues don’t hesitate to post into comment and I will respond promptly if I can help.






#1 by Ala' Abuhijleh on July 3, 2012 - 13:31
Quote
My application just crashes when fb.init is called! can you help me
#2 by Ala' Abuhijleh on July 3, 2012 - 13:52
Quote
I tried everything possible but I keep getting the following
07-03 10:50:25.208: I/dalvikvm(1237): threadid=12: stack overflow on call to Landroid/util/Log;.println_native:IIILL
07-03 10:50:25.208: I/dalvikvm(1237): method requires 16+20+0=36 bytes, fp is 0×49638310 (16 left)
07-03 10:50:25.208: I/dalvikvm(1237): expanding stack end (0×49638300 to 0×49638000)
07-03 10:50:25.223: I/dalvikvm(1237): Shrank stack (to 0×49638300, curFrame is 0x4963bfe4)
07-03 10:50:25.223: W/dalvikvm(1237): threadid=12: thread exiting with uncaught exception (group=0x409c01f8)
07-03 10:50:25.728: D/dalvikvm(1237): GC_CONCURRENT freed 334K, 5% free 9521K/9927K, paused 5ms+4ms
07-03 10:50:25.798: E/AndroidRuntime(1237): FATAL EXCEPTION: Thread-116
07-03 10:50:25.798: E/AndroidRuntime(1237): java.lang.StackOverflowError
07-03 10:50:25.798: E/AndroidRuntime(1237): at android.util.Log.d(Log.java:138)
07-03 10:50:25.798: E/AndroidRuntime(1237): at org.apache.cordova.api.LOG.d(LOG.java:91)
07-03 10:50:25.798: E/AndroidRuntime(1237): at org.apache.cordova.DroidGap.getContext(DroidGap.java:943)
#3 by Tyler on August 1, 2012 - 00:45
Quote
Thanks for the great tutorial! I did this using cordova-1.7.0, and I had to make these minor changes:
1. in Facebook.java and FBDialog.java (two of the files from step 7), I removed the @override lines that caused errors.
2. I was still getting “android.os.NetworkOnMainThreadException” in my program on login, and this would cause my program to crash. It has to do with login running on the main thread, and if you are having this problem, this post was helpful.
These two changes solved my problems, hopefully that helps to anyone running into problems.
#4 by Tyler on August 1, 2012 - 00:47
Quote
Oops, too hasty on the last post. The link I was referring to in step 2 of my comment above can be found here:
http://stackoverflow.com/questions/10757577/networkonmainthreadexception-on-facebook-login-with-phonegap-1-6-0
#5 by Lala Waghmode on November 20, 2012 - 16:09
Quote
Thanks, Its great tutorial and working fine. I have to use like button for phonegap App.
can you please help me to get out of it.
#6 by prasad on April 2, 2013 - 21:43
Quote
Thnks,this code is working fine and great tutorial…..
#7 by Amit Lguru on May 7, 2013 - 15:57
Quote
this information is very useful for my project. i implemented all the steps that u explain.