-
-
Save anderson631/f52d8c3c692419b4ef7c to your computer and use it in GitHub Desktop.
Exemplo de login com Facebook no ionic + Cordova Oauth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$scope.facebookLogin = function() { | |
var facebook_appId = '...'; | |
$cordovaOauth.facebook(facebook_appId, ['email', 'user_birthday', 'user_location']).then(function(result) { | |
$http.get('https://graph.facebook.com/v2.5/me', { params: { access_token: result.access_token, fields: 'id,name,email,gender,location,picture', format: 'json' }}).then(function(result) { | |
var usuarioBD = { | |
usuario_id_facebook: result.data.id, | |
usuario_nome: result.data.name, | |
usuario_email: result.data.email, | |
usuario_endereco_cidade: result.data.location.name | |
} | |
// Cadastra usuário no banco de dados | |
$http.post('http://exemplo.com.br/usuario/cadastrar/facebook', usuarioBD) | |
.success(function(data) { | |
alert('Usuário via Facebook cadastrado com sucesso.'); | |
}) | |
.error(function(data, status) { | |
alert('Algo de errado aconteceu ao criar conta via Facebook: '+status); | |
}); | |
}, function(error) { | |
alert('Erro ao retornar dados do Facebook: '+error); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment