简体   繁体   English

如何使用 react-native-fbsdk 提供的 LoginManager 从 Facebook 注销?

[英]How to logout from facebook with LoginManager provided by react-native-fbsdk?

In simple, how does one log out with LoginManager provided by react-native-fbsdk?简单来说,如何使用 react-native-fbsdk 提供的 LoginManager 登出?

If we look the code inside that LoginManager provided by react-native-fbsdk, we find this part regarding logout :如果我们查看 react-native-fbsdk 提供的 LoginManager 中的代码,我们会发现这部分是关于logout 的

  logOut() {
    LoginManager.logOut();
  },

So no callback, or promise?所以没有回调,或承诺? How do I really use this then?那我该如何真正使用它呢? If I call LoginManager.logout() , it actually does perform the logout.如果我调用LoginManager.logout() ,它实际上会执行注销。 But since I'm not allowed to pass any callback, and since it doesn't return a promise, then how do I know when the logout is done, or that was it successfull?但是由于我不允许传递任何回调,并且由于它不返回承诺,那么我怎么知道注销何时完成,或者是否成功? I tried providing a callback, but it resulted in error.我尝试提供回调,但导致错误。 I also tried to return a promise from it, but it also returned an error.我也试图从中返回一个承诺,但它也返回了一个错误。 So I don't know how is this supposed to be used?所以我不知道这应该如何使用? It can't be synchronous logout, right?不可能是同步注销吧?

I think its not a synchronous function but also I think you don't need to wait for it to finish.我认为它不是同步功能,但我认为您不需要等待它完成。 You can just use it as synchronous.您可以将其用作同步。 I'm thinking this because if you check the default LoginButton on react-native-fbsdk onLogoutFinished prop doesn't pass any parameters about the logout action (successful, failed etc.).我在想这是因为如果您检查react-native-fbsdk LoginButton上的默认LoginButton onLogoutFinished prop 不会传递有关注销操作的任何参数(成功、失败等)。 This means you can assume that its gonna happen without any problem since facebook itself assumed that.这意味着你可以假设它会毫无问题地发生,因为 facebook 本身就是这么认为的。 Default LoginButton listens for events to run onLogoutFinished function.默认LoginButton 侦听事件以运行onLogoutFinished函数。 You can try to implement something like that if you really need to.如果你真的需要,你可以尝试实现类似的东西。

For me, this works:对我来说,这有效:

import { LoginManager } from 'react-native-fbsdk'
LoginManager.logOut()

Actually after successfully login out the acsessToken becomes null.So after calling loginmanager.logout() you can check the accesstoken with AccessToken.getCurrentAccessToken() and if it comes null then you can safely assume that the logout has happened successfully.实际上,成功登录后, acsessToken 变为空。因此,在调用 loginmanager.logout() 后,您可以使用 AccessToken.getCurrentAccessToken() 检查访问令牌,如果它为空,则您可以放心地假设注销已成功发生。

LoginManager.logOut();
const token = await AccessToken.getCurrentAccessToken();
if(_.isEmpty(token) {/* your code for doing logout related actions */}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React-native-fbsdk ShareDialog。 如何与预填充的邮件和照片内容一起共享? - React-native-fbsdk ShareDialog. How to share with prefilled message and photos content together? 当请求更多的数据而不仅仅是invitable_friends数据时,如何在react native(react-native-fbsdk)中请求更大的图像? - How do I ask for larger images in react native (react-native-fbsdk) when asking for more then just invitable_friends data? react-native-fbsdk 中的“user_posts”权限无效,尽管它已通过审核 - Invalid permission “user_posts” in react-native-fbsdk although it is approved by review react-native在Facebook登录和注销后如何刷新页面 - react-native how to refresh the page after facebook log and logout React Native FBSDK中的AccessToken问题 - Issues with the AccessToken in the React Native FBSDK 在React Native中单击注销按钮后,如何从登录屏幕导航? - How navigate from loginscreen after clicking on logout button in react native? 如何在 React Native 的抽屉中添加注销按钮 - How to Add Logout Button In Drawer in React Native (本机)可能未处理的承诺拒绝FBSDK - (React-Native) Possible Unhandled Promise Rejection FBSDK 如何在 React Native 上更正我的注销 function? - How can I correct my logout function on React Native? 如何在 React Native 中登录和注销后在 2 个不同的导航器之间导航 - How to navigate between 2 different navigators after login and logout in react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM