2016-10-08 14 views
0

私は Facebookで私のアプリへのログインをやろうとしている私は、コルドバのFacebookのプラグインionic2 Facebookのログインではない成功

enter image description here

と、この私のコードをインストールしますが、私は約束 enter image description here

上のエラーを取得します

これは私のコード(実際に私はちょうどそれが彼のために働くと言うのチュートリアルから、それをコピーした)

import { Component } from '@angular/core'; 
import { NavController,Platform } from 'ionic-angular'; 
import {Http, Headers, RequestOptions} from '@angular/http'; 
import 'rxjs/add/operator/map'; 


declare const facebookConnectPlugin: any; 

@Component({ 
    templateUrl: 'build/pages/home/home.html', 
}) 
export class HomePage { 
    posts:any; 
    constructor(public platform: Platform, private navCtrl: NavController,private http: Http) 
    { this.platform = platform; 
    this.http = http; 
    } 

    fblogin() 
    { 
    this.platform.ready().then(() => { 
     this.fblogin1().then(success => { 
     console.log("facebook data===" + success); 
     alert("facebook data===" + success); 
     this.http.post('http://localhost/facebook.php',success) 
      .map(res =>res.json()).subscribe(data => { 
      if(data.msg=="fail") 
      { 
      console.log('Login failed'); 
      alert("Invalid username and password"); 
      return; 
      } 
      else 
      { 
      console.log(' login Sucessfully facebook'); 
      } 
     }); 
     }, (error) => { 
     alert(error); 
     }); 
    }); 
    } 
    fblogin1(): Promise<any> 
    { 
    return new Promise(function(resolve,reject) 
    { 
     facebookConnectPlugin.login(["email"], function(response) 
      { 
      alert(JSON.stringify(response.authResponse)); 
      facebookConnectPlugin.api('/' + response.authResponse.userID + '?fields=id,name,email,gender',[], 
       function onSuccess(result) 
       { 
//alert(JSON.stringify(result)); 
//console.log(JSON.stringify(result)); 
        resolve(JSON.stringify(result)); 
       }, 
       function onError(error) 
       { 
        alert(error); 
       } 
      ); 
      }, 
      function(error) 
      { 
      alert(error); 
      }) 
    }); 
    } 

} 
です0

誰かが私が知りたいと思う別の方法を知っていれば。

+0

をログイン機能を変更することで、この問題を解決uがこの問題を解決しましたか?私は同じ問題を抱えています –

+0

@KingsleySimonはい、私はちょうど私の解決策を公開しました –

答えて

0

私は、このコードに

facebookLogin(){ 

Facebook.login(['email']).then((response) => { 
    let facebookCredential = firebase.auth.FacebookAuthProvider 
     .credential(response.authResponse.accessToken); 
    var that = this; 
    firebase.auth().signInWithCredential(facebookCredential) 
     .then((success) => { 

     that.userProfile = JSON.stringify(success); 

     that.nav.setRoot(HomePage);// after login go to HomePage 
     }) 
     .catch((error) => { 
     console.log("Firebase failure: " + JSON.stringify(error)); 
     }); 

}).catch((error) => { console.log(error) }); 

}

関連する問題