Last active
August 29, 2015 13:56
-
-
Save BobNisco/8834810 to your computer and use it in GitHub Desktop.
Getting started with PhoneGap 3.x Facebook Login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- If you're using PhoneGap Build --> | |
<feature name="org.apache.cordova.facebook.Connect"> | |
<param name="android-package" value="org.apache.cordova.facebook.ConnectPlugin" /> | |
</feature> | |
<!-- Cordova Plugin --> | |
<gap:plugin name="com.phonegap.plugins.facebookconnect"> | |
<param name="APP_ID" value="YOUR_FB_APP_ID" /> | |
<param name="APP_NAME" value="YOUR_APP_NAME" /> | |
</gap:plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="YOUR_FB_APP_ID" --variable APP_NAME="YOUR_APP_NAME" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof CDV === 'undefined') { | |
alert('CDV variable does not exist. Check that you have included cdv-plugin-fb-connect.js correctly'); | |
} | |
if (typeof FB === 'undefined') { | |
alert('FB variable does not exist. Check that you have included the Facebook JS SDK file.'); | |
} | |
document.addEventListener('deviceready', function() { | |
try { | |
FB.init({ | |
appId: "YOUR_FB_APP_ID", | |
nativeInterface: CDV.FB, | |
useCachedDialogs: false | |
}); | |
} catch (e) { | |
alert(e); | |
} | |
}, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var loginButton = $('#login-with-facebook'); | |
loginButton.on('click', function(e) { | |
e.preventDefault(); | |
FB.login(function(response) { | |
if (response.status === 'connected') { | |
alert('logged in'); | |
} else { | |
alert('not logged in'); | |
} | |
},{ scope: "email" }); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment