Using the cordova-plugin-facebook4
refering the docs from the offcial docs
also refering the docs from the ionic facebook native docs
CODE
auth-service :
public loginFacebook() {
return Observable.create(observer => {
let permissions = new Array(); permissions = ["public_profile"]; Facebook.login(permissions) .then(function(response){ let userId = response.authResponse.userID; let params = new Array(); Facebook.api("/me?fields=id,name,gender,email", params) .then(function(user) { // loader.present(); user.picture = "https://graph.facebook.com/" + userId + "/picture?type=large"; //now we have the users info observer.next(user); observer.complete(); }) }, function(error){ console.log(error); });
});
}
in login.ts :
this.auth.loginFacebook().subscribe(function(data){
loader.present(); let toPost = { id:data.id, name:data.name, email:data.email, picture:data.picture } console.log("facebook login", toPost.id,toPost.name,toPost.email,toPost.picture); let json = JSON.stringify(toPost); let headers = new Headers(); headers.append('Content-Type', 'application/json');
///**problem start down here -- no response whatsoever**//
this.http.post(this.appUrl + 'facebook/login', json,{headers: headers}) .subscribe((data :any ) => { setTimeout(() => loader.dismiss() ,500); console.log("facebook login",data._body); }) })
Question: Why can’t i make a http.post within the subscribe block after facebook auth? There is no response whatsoever from http.post. The loading also is not stopping, seems like the post never actually posted. i surely can make an http.post outside facebook auth function. Is there anything i should know?