首页 > 解决方案 > 使用 twitter 登录 Firebase 在 React Native 中不起作用

问题描述

我正在尝试在反应本机应用程序的 Frebase 身份验证中使用 twitter。我正在使用以下代码来做到这一点

      const { RNTwitterSignIn } = NativeModules;

      RNTwitterSignIn.init(TwitterKeys.TWITTER_CONSUMER_KEY, TwitterKeys.TWITTER_CONSUMER_SECRET)

          RNTwitterSignIn.logIn()
            .then(loginData => {
              console.log("loginData="+loginData.authToken + " "+ loginData.authTokenSecret)
              console.log(JSON.stringify(loginData));
              const credential = firebase.auth.GoogleAuthProvider.credential(loginData.authToken, loginData.authTokenSecret)

              return firebase.auth().signInWithCredential(credential);

            }).then((currentUser)=>{
              this.props.navigation.navigate('FlyerListing')

              //--------------------------Async Test--------------------------
                AsyncStorage.setItem("user", currentUser.uid)
                console.log("AsyncStorage= "+ currentUser.uid)
            //--------------------------------------------------------------
            })
            .catch(error => {
              console.log(error)
            })

当我尝试登录时,我在控制台中收到以下错误:-

{代码:“auth/invalid-credential”,消息:“无法解析 Google id_token:150550928-ZJgBitL44wrST6DKCWhUx9b2dmNo10RGyQZ”}

我怎样才能解决这个问题。

注意:-我使用相同的方法登录谷歌并且工作正常

标签: androidfirebasereact-nativetwitterfirebase-authentication

解决方案


我找到了。我正在使用 const

凭证 = firebase.auth.GoogleAuthProvider.credential(loginData.authToken, loginData.authTokenSecret)

安装的

const credential = firebase.auth.TwitterAuthProvider.credential(loginData.authToken, loginData.authTokenSecret)


推荐阅读