I think you should use the facebook phonegap plugin as your authentication.
Download and install cordova into your project.
https://github.com/phonegap/phonegap-facebook-plugin
Use this command to install it.
cordova plugin add https://github.com/phonegap/phonegap-facebook-plugin.git --variable APP_ID="xxxxxxxxxxxxx" --variable APP_NAME="xxxxxxxx"
Then set up your facebook app here:
http://developers.facebook.com/apps/
Then make sure you have this script in your project.
cdv-plugin-fb-connect.js facebook-js-sdk.js
After that, paste this code into your main script
if ((typeof cordova == 'undefined') && (typeof Cordova == 'undefined')) alert('Cordova variable does not exist. Check that you have included cordova.js correctly'); 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.'); FB.Event.subscribe('auth.login', function(response) { //alert('auth.login event'); }); FB.Event.subscribe('auth.logout', function(response) { //alert('auth.logout event'); }); FB.Event.subscribe('auth.sessionChange', function(response) { //alert('auth.sessionChange event'); }); FB.Event.subscribe('auth.statusChange', function(response) { //alert('auth.statusChange event'); }); function getSession() { alert("session: " + JSON.stringify(FB.getSession())); } function getLoginStatus() { FB.getLoginStatus(function(response) { if (response.status == 'connected') { alert('logged in'); } else { alert('not logged in'); } }); } var friendIDs = []; var fdata; function logout() { FB.logout(function(response) { alert('logged out'); window.location.replace("#login"); }); } function login() { FB.login( function(response) { if (response.authResponse) { alert('logged in'); FB.api('/me', function(me) { if (me.id) { localStorage.id = me.id; localStorage.email = me.email; localStorage.name = me.name; window.location.replace("#home"); } else { alert('No Internet Connection. Click OK to exit app'); navigator.app.exitApp(); } }); } else { alert('not logged in'); } }, { scope: "email" }); } document.addEventListener('deviceready', function() { try { //alert('Device is ready! Make sure you set your app_id below this alert.'); FB.init({ appId: "appid", nativeInterface: CDV.FB, useCachedDialogs: false }); document.getElementById('data').innerHTML = ""; } catch (e) { alert(e); } }, false);
use login() to log in. Enjoy !!
source share