首页 > 解决方案 > Expo facebook 身份验证方法或属性在网络上不可用

问题描述

我正在尝试使用文档中的登录代码使用 Expo SDK 38 创建一个登录 Facebook:

import * as Facebook from "expo-facebook";

export async function signInWithFacebook() {

  try {
    await Facebook.initializeAsync("688582288586140");
    const {
      type,
      token,
      expires,
      permissions,
      declinedPermissions,
    } = await Facebook.logInWithReadPermissionsAsync({
      permissions: ["public_profile"],
    });
    if (type === "success") {
      // Get the user's name using Facebook's Graph API
      const response = await fetch(
        `https://graph.facebook.com/me?access_token=${token}`
      );
      Alert.alert("Logged in!", `Hi ${(await response.json()).name}!`);
    } else {
      // type === 'cancel'
    }
  } catch ({ message }) {
    alert(`Facebook Login Error: ${message}`);
  }
}

我收到以下错误:

The method or property Facebook.initializeAsync is not available on web, are you sure you've linked all the native dependencies properly?

这是我的 package.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "^38.0.0",
    "expo-facebook": "~8.2.1",
    "expo-splash-screen": "~0.3.1",
    "expo-status-bar": "^1.0.0",
    "firebase": "7.9.0",
    "react": "16.11.0",
    "react-dom": "16.11.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-38.0.0.tar.gz",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "babel-preset-expo": "^8.2.3"
  },
  "private": true
}

我已经尝试重新安装所有依赖项,并且我还尝试了其他版本的 expo-facebook,但没有成功,我做错了什么?

标签: react-nativeexpo

解决方案


Expo web 的 Facebook Auth 还没有准备好。您可以在这里跟踪取得的进展:https ://github.com/expo/expo/pull/6862

我们所能做的就是等待专业人士为我们处理此功能。当然,我们也可以为开源做出贡献。


推荐阅读