使用react-native-fbsdk LoginManager时如何设置LoginBehaviour? [英] How do I set LoginBehaviour when using react-native-fbsdk LoginManager?

查看:266
本文介绍了使用react-native-fbsdk LoginManager时如何设置LoginBehaviour?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用react-native-fbsdk中的LoginButton,则LoginBehaviour似乎是本机",因为SDK与已安装的FB应用程序通信,看到我已经被授予权限,并且仅登录我而未显示任何对话框等

If I use the LoginButton from react-native-fbsdk the LoginBehaviour seems to be "native" in that the SDK communicates with the installed FB app, sees that I've already granted permissions and just logs me in without showing any dialogs, etc.

当我使用LoginManger.logInWithPublishPermissions()机制时,我总是被带到浏览器和一个屏幕,上面说我已经对我的应用程序授予了权限.我想我可以通过设置登录行为来更改此设置,但是我不知道如何成功完成该操作.这是我尝试过的

When I use the LoginManger.logInWithPublishPermissions() mechanism I'm always taken to the brower and a screen that says I've already given permission to my app. I assume I can change this by setting the login behaviour, but I can't figure out how to do that successfully. Here's what I've tried

import { GraphRequest, GraphRequestManager, LoginManager, LoginBehaviorIOS } from 'react-native-fbsdk';
LoginManager.setLoginBehavior(LoginBehaviorIOS);

//ERROR: Argument 0 (FBSDKLoginBehaviour) of FBLoginManager: must not be null

然后我尝试了这个:

LoginManager.setLoginBehavior('native');

// No error, but still gives me the same behaviour.

LoginButton和LoginManager的行为何时有所不同?使用LoginManager时如何设置登录行为,使其像LoginButton一样工作?

When do LoginButton and LoginManager act differently? How do I set the login behaviour when using LoginManager so it works like the LoginButton?

我已将所有代码添加到AppDelegate.m文件中,并在《入门指南》中添加了所有其他说明:

I've added all of the code to the AppDelegate.m file and all other instructions included in the Getting Started Guide: https://developers.facebook.com/docs/ios/getting-started/

推荐答案

我遇到了类似的问题,并通过如下设置登录行为设法使其正常工作:

I had a similar issue and managed to make it work by setting the login behavior as follows:

LoginManager.setLoginBehavior('NATIVE_ONLY'); 

即使在关于本主题的react-native-fbsdk GitHub repo 中,Facebook文档也很差:(

Facebook documentation is poor even in react-native-fbsdk GitHub repo about the subject :(

使用natie_only行为有一个陷阱.用户必须在此电话上安装FB,否则FB SDK会静默失败.为了解决这个问题,我决定在native_only失败的情况下启动WEB_ONLY行为.我的示例已针对Android(而非iOS)进行了测试.

There is a catch by using natie_only behavior. User must have FB installed at this phone, otherwise the FB SDK fails silently. To address that I decided to launch the WEB_ONLY behavior in case the native_only fails. My example is tested for Android, not iOS yet.

let result;
try {
  LoginManager.setLoginBehavior('NATIVE_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
} catch (error) {
  LoginManager.setLoginBehavior('WEB_ONLY');
  result = await LoginManager.logInWithReadPermissions(['public_profile', 'email']);
}

编辑编辑: 我在如何在React Native中使用Facebook SDK ,我提到了更多的东西(即如何执行图形请求).如果需要有关此主题的更多信息,请查看.

EDIT EDIT: I published an article on how to use Facebook SDK in React Native where I mention more stuff (i.e. how to perform graph requests). Check it out if you need more info on the subject.

这篇关于使用react-native-fbsdk LoginManager时如何设置LoginBehaviour?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆