2017-08-02 145 views
0

我想在我的反應原生應用程序中使用Facebook登錄..我使用web上的firebase(reactJs)..現在我使用相同的方法來反應原生應用程序,但它不工作.. 。如何使用Facebook登錄反應本機應用程序

我想fbSignin按鈕,允許我使用用戶的個人資料相片和姓名等。

這裏是我的代碼..

import React, { Component } from "react" 
import { Container, Item, Button, Text } from "native-base" 
import * as firebase from "firebase" 
import { FBLogin, FBLoginManager } from "react-native-facebook-login" 

// Initialize Firebase 

var config = { 
    apiKey: "AIzaSyAK7dr25d-qnsHCdvkeoVPWs7Q0", 

    authDomain: "quiz-appasdn-ba8c1.firebaseapp.com", 

    databaseURL: "httpsasdasdasdasd-ba8c1.firebaseio.com", 

    projectId: "quiz-asdaasdasdc1", 

    storageBucket: "pplicationasdasd-asddappspot.com", 

    messagingSenderId: "23764257465237" 

}; 

firebase.initializeApp(config); 



var provider = new firebase.auth.FacebookAuthProvider(); 


class App extends Component { 

    fbLogin() { 

    firebase.auth().signInWithPopup(provider).then(function (result) { 

     var token = result.credential.accessToken; 

     var user = result.user; 

    }).catch(function (error) { 

     var errorCode = error.code; 

     var errorMessage = error.message; 

     var email = error.email; 

     var credential = error.credential; 

    }); 

    } 



    render() { 

    return (

     <Button onPress={this.fbLogin.bind(this)}> 

     <Text>faacebook Login</Text> 

     </Button> 
    ); 
    } 
}; 

出口默認應用

感謝提前..

+0

請從帖子中刪除API密鑰 – XPLOT1ON

回答

0

firebase.auth().signInWithPopup(provider)不適合的反應母語,你必須使用firebase.auth().signInAndRetrieveDataWithCredential(credential)react-native-fbsdk一起簽署工作在與Facebook ..
這裏是片段

 <LoginButton 
     onLoginFinished={ 
     (error, result) => { 
      if (error) { 
      alert("login has error: " + result.error); 
      } else if (result.isCancelled) { 
      alert("login is cancelled."); 
      } else { 
      AccessToken.getCurrentAccessToken().then(
       (data) => { 
       const provider = firebase.auth.FacebookAuthProvider; 
       const credential = provider.credential(data.accessToken.toString()); 
       firebase.auth().signInAndRetrieveDataWithCredential(credential) 
       .then(function(userCredential) { 
        console.log(JSON.stringify(userCredential)); 
       }); 
       } 
      ) 
      } 
     } 
     } 
     onLogoutFinished={() => alert("logout.")}/> 

資源:
Facebook React Native SDK
Firebase signInAndRetrieveDataWithCredential

相關問題