Skip to content

Instantly share code, notes, and snippets.

@edyonil
Created February 23, 2016 11:33
Show Gist options
  • Save edyonil/5644e709e286b86c0787 to your computer and use it in GitHub Desktop.
Save edyonil/5644e709e286b86c0787 to your computer and use it in GitHub Desktop.
loginCtrl.facebook = function () {
$cordovaOauth.facebook("MINHA_CHAVE", ['email']).then(function (result) {
displayData(result.access_token);
}, function (error) {
console.log(JSON.stringify(error))
});
};
function displayData(access_token) {
$ionicLoading.show({
template: '<ion-spinner></ion-spinner>'
});
$http.get("https://graph.facebook.com/v2.5/me", {
params: {
access_token: access_token,
fields: 'name, email',
format: "json"
}
}).then(function (result) {
var nome = __resolveName(result.data.name);
var dados = {
nome: nome[0],
sobrenome: nome[1],
email: result.data.email,
token: access_token
};
User.createUser('facebook', dados).then(function (data) {
__createLocalStorage(data);
$ionicLoading.hide();
$state.go('app.home');
}, function (error) {
$ionicLoading.hide();
$ionicPopup.alert({
title: "Error!",
template: error
});
});
}, function (error) {
alert("Error: " + JSON.stringify(error));
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment