Skip to content

Instantly share code, notes, and snippets.

@BobNisco
Last active August 29, 2015 13:56
Show Gist options
  • Save BobNisco/8834810 to your computer and use it in GitHub Desktop.
Save BobNisco/8834810 to your computer and use it in GitHub Desktop.
Getting started with PhoneGap 3.x Facebook Login
<!-- 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>
cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="YOUR_FB_APP_ID" --variable APP_NAME="YOUR_APP_NAME"
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);
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