Skip to content

Instantly share code, notes, and snippets.

@waqasy
Created Oct 24, 2015
Embed
What would you like to do?
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