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 Jeroen on January 29, 2012 - 20:29
Quote
Sorry, but i am stuck on step 5. Could you tell me where i can find the Java source file? Should I Modify this file?
Thanks!
#2 by smartman on January 29, 2012 - 20:37
Quote
Step 6 describes including file needed for native coding for PhoneGap Facebook plugin. Current latest version can be seen in plaintext from https://raw.github.com/davejohnson/phonegap-plugin-facebook-connect/bdac0f1e488aa4b27a59282b164ce8b7e2079873/native/android/src/com/phonegap/facebook/ConnectPlugin.java
Create package com.phonegap.facebook and add ConnectPlugin.java source there.
Did this help?
#3 by BrianH on February 1, 2012 - 18:18
Quote
Thanks for explaining the steps to get this running. I am getting stuck on step #8. I’m not sure which file you are referring to.
Do you have a basic sample code that you could attach as a zip so that we could download it and see the directory structure and how you have everything setup?
thanks
#4 by smartman on February 1, 2012 - 22:42
Quote
Step 8 describes editing files imported in step 7. https://github.com/facebook/facebook-android-sdk/tree/master/facebook/src/com/facebook/android has listed all the native .java files in package com.facebook.android. All other files are OK except FbDialog.java. Add there line “import com.myproject.R;” . “com.myproject” is your android package name.
#5 by AhmadW on February 10, 2012 - 04:51
Quote
It works very well. Thank you very much.
#6 by hoff on March 1, 2012 - 14:15
Quote
this works (with the help of the comments), thanks for posting!
#7 by Daniel on March 2, 2012 - 13:33
Quote
I get this error message: “ReferenceError: Can’t find variable: lid”
What could be the reason?
#8 by Daniel on March 2, 2012 - 14:12
Quote
Sorry… nothing to do with the facebook plugin!
#9 by Anonymous on March 7, 2012 - 18:50
Quote
Thanks for the tut. I tried to post messages to users wall and got the error code 200: saying the user did not grant any permission. How can i post to facebook walls
#10 by smartman on March 7, 2012 - 19:05
Quote
try
FB.login(function(response) {
// handle the response
}, {scope: ‘publish_stream’});
See also https://developers.facebook.com/docs/reference/javascript/FB.login/
#11 by slimtugo on March 8, 2012 - 05:26
Quote
I already tried that. Maybe oauth2 isn’t supported and the plugin is using an older facebook sdk.
#12 by Bassem on March 11, 2012 - 14:12
Quote
Works great, thanks a lot, you don’t know how it was frustrating not to find a handful guide
you rock man
#13 by Las on March 11, 2012 - 21:42
Quote
Thanks for the tutorial!
I am getting an error, maybe you can help please,
see here: http://imgur.com/a/fxEzf
#14 by I am getting this error! on March 13, 2012 - 21:59
Quote
com.phonegap.facebook.Connect3 = TypeError: Object # has no method ‘setAuthResponse’
#15 by I am getting this error! on March 13, 2012 - 22:12
Quote
Error in success callback: com.phonegap.facebook.Connect3 = TypeError: Object # has no method ‘setAuthResponse’
Is your patched file the latest version?
Thanks
#16 by slimtugo on March 14, 2012 - 03:31
Quote
Can i post to wall with this?
#17 by sekhar on March 21, 2012 - 15:46
Quote
I am not able to login not even with the help of previous comments. please help
#18 by Ben Longstaff on March 27, 2012 - 02:56
Quote
Awesome tutorial the things that caught me out where
1. generating the hash to put into the Android app, this post helped me solve that
http://stackoverflow.com/questions/5306009/facebook-android-generate-key-hash
2. the deviceReady not always getting called, the solution i found was
http://www.philliprhodes.com/content/phonegap-deviceready-not-called-android
I also found that uninstalling the app i was working on and redeploying it from eclipse resolved alot of odd behaviour.
#19 by Ben Longstaff on March 27, 2012 - 04:13
Quote
Ah seems I am getting the error
Error in success callback: com.phonegap.facebook.Connect1 = TypeError: Object # has no method ‘setAuthResponse’
as well
#20 by Mark Walls on April 15, 2012 - 19:48
Quote
I am getting stuck on step 4 basically. I am getting a compile error saying the XML is not clearly formed. I’ve already done the rest of the steps from this article (much clearer than the phonegap version. Thank you). Any thoughts?
#21 by idanb on April 15, 2012 - 22:59
Quote
Hi .
Thanks for this help ,
I’m stuck , I went through all comments and steps and I’ve got this errors :
Description Resource Path Location Type
close cannot be resolved or is not a field FbDialog.java /SocialLogin/src/com/facebook/android line 106 Java Problem
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 50 Java Problem
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 123 Java Problem
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 193 Java Problem
The method logout(Context) in the type Facebook is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 121 Java Problem
The method onClick(View) of type new View.OnClickListener(){} must override a superclass method FbDialog.java /SocialLogin/src/com/facebook/android line 101 Java Problem
The method onServiceConnected(ComponentName, IBinder) of type Facebook.TokenRefreshServiceConnection must override a superclass method Facebook.java /SocialLogin/src/com/facebook/android line 575 Java Problem
The method onServiceDisconnected(ComponentName) of type Facebook.TokenRefreshServiceConnection must override a superclass method Facebook.java /SocialLogin/src/com/facebook/android line 581 Java Problem
help ?
#22 by Mark Walls on April 17, 2012 - 06:14
Quote
Wondering if anyone actually gets this working – it would be awesome of you to put up a github of the code so we can see what we are doing wrong. Just post a link here. Thanks.
#23 by idanb on April 18, 2012 - 17:33
Quote
me 2
#24 by Nino Nikowa on April 20, 2012 - 13:52
Quote
Set java compiler -> 1.6
http://androidcodemonkey.blogspot.com/2011/10/how-to-solve-must-override-superclass.html
Pingback: PhoneGap Facebook Plugin connect with android | Build Future Repository
#25 by idanb on April 21, 2012 - 11:33
Quote
thank you …
still ..
errors :
Description Resource Path Location Type
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 51 Java Problem
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 124 Java Problem
The method getDefaultSharedPreferences(Context) in the type PreferenceManager is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 194 Java Problem
The method logout(Context) in the type Facebook is not applicable for the arguments (CordovaInterface) ConnectPlugin.java /SocialLogin/src/com/phonegap/facebook line 122 Java Problem
#26 by idanb on April 23, 2012 - 20:33
Quote
Fixed by moving the packages to the root ….
Still it doent work :
* I have web app id at facebook (should i have native one ?)
* How do I get my app signature that facebook asks for?
i’m using eclipse hellios + phonegap 1.5 under windows 7
thanks for helpers ….
#27 by Kamlesh on April 24, 2012 - 14:55
Quote
What should be config.xml file structure for generating files for iOS and other operating system for facebook app
#28 by idanb on April 24, 2012 - 19:59
Quote
I’ve got this from the logcat …
Error adding plugin org.apache.cordova.facebook.ConnectPlugin.
help !
#29 by idanb on April 25, 2012 - 15:48
Quote
again logcat :
/CordovaLog(334): file:///android_asset/www/cordova-1.5.0.js: Line 783 : Error: Status=2 Message=Class not found
#30 by idanb on April 27, 2012 - 18:56
Quote
Tried again with 1.6.1 , no luck
error in compilation :
Description Resource Path Location Type
close cannot be resolved or is not a field FbDialog.java /FaceLogIn/src/com/facebook/android line 106 Java Problem
what say you ?
#31 by Vinay on April 28, 2012 - 08:07
Quote
Trying with cardova 1.6.0 , getting alerts
1. Cordova Facebook Connect plugin fail on login!
2. Cordova Facebook Connect plugin fail on auth.status!
pls help
Trackback: web exploits
#32 by Rav on April 30, 2012 - 22:44
Quote
I am getting the following error. Anyone have a fix for it. -Thx Error in success callback: com.phonegap.facebook.Connect3 = TypeError: Object # has no method ‘setAuthResponse’ at file:///android_asset/www/phonegap-1.4.1.js:692
#33 by smartman on May 2, 2012 - 14:43
Quote
To solve the above issues is easiest way to download the eclipse source package I made available. Once you get this simple program running you can compare to your own solution.
#34 by idanb on May 4, 2012 - 21:54
Quote
Thanks smartman , can you explain here wich folder from the download link we need to import to the eclipse ?
(FacebookTest)
Detailed guide would be gratetude .
thanks again !
#35 by Sugarfixx on May 12, 2012 - 13:24
Quote
Thanks a lot for this very straight forward tutorial on how to get the FB plugin to work on android. I just wanted to inform you all that is also works just fine with cordova-1.7.0 and to those og you that strugles with step 8, just du exactly what it says!
(I got that right on second attempt)
#36 by Sugarfixx on May 12, 2012 - 13:29
Quote
Oh just forgot.. regardig the manifest.xml (included in the example) did not work without adding the following lines of code (that we all know so well)
#37 by Sugarfixx on May 12, 2012 - 13:31
Quote
#38 by Sugarfixx on May 12, 2012 - 13:38
Quote
Sorry difficult to post code to a WordPress!!!
#39 by siva on May 16, 2012 - 10:42
Quote
Awesome tutorial ,works great.Thanks a lot. please help me how to post message.
#40 by Wes Turner on May 16, 2012 - 21:04
Quote
Can I tell you that the R.drawable issue was KILLING me? Thanks so much for the detailed instructions. I wonder why it’s sooo hard for the jar files not to include these appropriately so that the sources don’t have to be compiled.
#41 by Michael on May 17, 2012 - 03:42
Quote
I built an example project using Cordova 1.7.0 and the Facebook plugin. The Hackbook example is also integrated. https://github.com/rezbuilt/facebook-connect-phonegap-framework
#42 by Santanu from mobiquest on May 22, 2012 - 06:23
Quote
No comments are enough for this tutorial. Really awesome..
Thanks buddy…..
#43 by Patrick on June 1, 2012 - 02:03
Quote
Hello, thanks so much for the tutorial. I want my users to be able to upload a photo to my server and to save each photo as theirs by categorizing it with their username or some unique ID. How can I get thise from the facebook plugin?
Thanks!
#44 by PksMob on June 4, 2012 - 09:54
Quote
Hello, I downloaded your sources, when I am pressing login button from Android emulator screen, it shows an alert: “Cordova Facebook Connect plugin fail on login!Dialog error: The connection to the server was unsuccessful.”
Could you hint any solution here? Thanks in advance!
#45 by PksMob on June 4, 2012 - 11:41
Quote
Pls ignore my previous comment, it was proxy problem. Its working for me too. Thanks!
#46 by Jasper Mogg on June 12, 2012 - 18:33
Quote
This is fantastic. Thank you so much, especially for the example download.
Cheers!
#47 by ipek on June 18, 2012 - 15:46
Quote
Trying with cardova 1.8.0 ,
I get these alerts:
1. Cordova Facebook Connect plugin fail on login!
2. Cordova Facebook Connect plugin fail on auth.status!
What can i do?
#48 by Giovani Arduini on June 24, 2012 - 23:43
Quote
same error with me!
Trying with cardova 1.8.0 ,
I get these alerts:
1. Cordova Facebook Connect plugin fail on login!
2. Cordova Facebook Connect plugin fail on auth.status!