react-native - 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,但没有成功,我做错了什么?
解决方案
Expo web 的 Facebook Auth 还没有准备好。您可以在这里跟踪取得的进展:https ://github.com/expo/expo/pull/6862
我们所能做的就是等待专业人士为我们处理此功能。当然,我们也可以为开源做出贡献。
推荐阅读
- php - Wordpress 将画廊转换为精美的盒子画廊
- node.js - 使用 Heroku 请求 mLab 超时
- python-2.7 - 带有 if、with、for 和 math-add 用法的 Django 模板操作
- javascript - Google 登录无法访问该帐户
- java - 如何从导出的 WAR 中排除不需要的 JAR
- c# - 在 WPF 中使用 MVVM 将过滤器文本框添加到组合框
- javascript - 关闭问题 - 嵌套的 for 循环只打印一次
- javascript - 如何在前端 js 文件中安装、导入和使用 DOMPurify?
- android - 从适配器到片段的 Android Studio 回调
- swift - 是否有可能获得具有默认参数的一流函数?