首页 > 解决方案 > 为什么我无法使用通过 firebase 从 facebook sdk 获得的凭据登录?

问题描述

嗨,我在使用 expo、facebook sdk 和 Firebase 登录 facebook 时出错

[Error: Unsuccessful debug_token response from Facebook: {"error":{"message":"Invalid OAuth access token.","type":"OAuthException","code":190,"fbtrace_id":"AM5hHHrnXuN4ehHi4q_mmR_"}}]

在我的控制台日志中,我可以看到正在接收凭据,但我仍然收到此错误,并且在我的 facebook 通知中我收到了我登录到此应用程序的通知,错误在 firebase signInWithCredential 中,也在 facebook 调试器上:https://developers .facebook.com/tools/debug/accesstoken/来自凭证日志的令牌是有效的,我的代码

import React from 'react'
import firebase from "firebase/app";
import "firebase/auth";
import {Button} from "react-native-paper";
import * as Facebook from "expo-facebook";

function FacebookLogin({appColor}) {

    firebase.auth().onAuthStateChanged(user => {
        if (user != null && !user.isAnonymous) {
            console.log('We are authenticated now!');
        }

        // Do other things
    });

    async function LoginWithFacebook() {
        await Facebook.initializeAsync({appId: '741443520140189', appName: 'Just an app'});
        const {type, token} = await Facebook.logInWithReadPermissionsAsync({
            permissions: ['public_profile'],
        });

        if (type === "success") {
            console.log("TOKEN", token)
            const credential = firebase.auth.FacebookAuthProvider.credential(token);
            console.log("credentials", credential)

            firebase
                .auth()
                .signInWithCredential(credential)
                .catch(error => {
                    console.log(error)
                });

        }
    }

    return <Button onPress={() => LoginWithFacebook()} color={"#fff"} style={{marginTop: "20%"}}>Login</Button>
}

export default FacebookLogin

标签: javascriptreact-nativefirebase-authenticationexpofacebook-javascript-sdk

解决方案


推荐阅读