controller.js CODE
$scope.FBLogin = function(){
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
console.log(response);
var fbresponse = FB.getAuthResponse();
console.log(fbresponse.userID);
var userName = fbresponse.userID,
accessToken = fbresponse.accessToken,
social ;
console.log("username.."+userName);
console.log("at.."+accessToken);
var socialService = new App42Social();
socialService.linkUserFacebookAccount(userName, accessToken,{
success: function(object) {
console.log("object.."+JSON.stringify(object));
var response = JSON.parse(object);
social = response.app42.response.social;
console.log("userName is " + social.userName)
console.log("fb Access Token is " + social.facebookAccessToken)
$state.go('tabsController.home');
},
error: function(error) {
console.log("error..;"+error);
}
});
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
}
html CODE
@@@ <button id="login-facebook" style="font-size:15px;border-radius:5px 5px 5px 5px;" class="button button-positive button-block" ng-click="FBLogin()">facebook login</button> @@@@
app.js CODE
window.fbAsyncInit = function() {
FB.init({
appId : '1663410043984668',
xfbml : true,
version : 'v2.7'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));