Skip to content

Instantly share code, notes, and snippets.

@waqasy
Created October 24, 2015 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waqasy/a0606779efc3378cf9b5 to your computer and use it in GitHub Desktop.
Save waqasy/a0606779efc3378cf9b5 to your computer and use it in GitHub Desktop.
Facebook Login
/**
* @author www.juliocanares.com/cv
* @email juliocanares@gmail.com
*/
var getJSUserData, loginUser, postToFacebook;
getJSUserData = function (callback) {
FB.getLoginStatus((function (response) {
if (response.status === "connected") {
callback(response, 1);
} else if (response.status === "not_authorized") {
callback(response, 0);
} else {
callback(response, 0)
}
}), true);
};
loginUser = function (callback) {
if (isMobile.any()) {
document.location.href = 'https://www.facebook.com/dialog/oauth?client_id=' + "APP_ID" + '&redirect_uri=' + document.location.href + '&scope=APP_PERMISSIONS';
}
else {
FB.login((function (response) {
if (response.authResponse) {
FB.api("/me", function (response) {
callback(response, true);
});
} else {
callback(response, false);
}
}), {
scope: 'APP_PERMISSIONS'
});
}
};
var isMobile = {
Android: function () {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function () {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function () {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function () {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function () {
return navigator.userAgent.match(/IEMobile/i);
},
any: function () {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment