如果我从react-native-fbsdk使用LoginButton,LoginBehaviour似乎是“本地的”,因为SDK与安装的FB应用程序通信,看到我已经授予权限,只让我登录而不显示任何对话框,等等。
我假设我可以通过设置登录行为来改变这一点,但我不知道如何成功地做到这一点。以下是我尝试过的方法
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一样工作?
我已经将所有代码添加到AppDelegate.m文件以及入门指南中包含的所有其他说明:https://developers.facebook.com/docs/ios/getting-started/
发布于 2017-11-13 23:27:28
我遇到了类似的问题,并设法通过如下设置登录行为来使其正常工作:
LoginManager.setLoginBehavior('NATIVE_ONLY'); 即使在react-native-fbsdk GitHub repo中,关于这个主题的Facebook文档也很糟糕:
编辑:通过使用natie_only行为有一个捕获。用户必须在该手机上安装FB,否则FB SDK会静默失败。为了解决这个问题,我决定启动WEB_ONLY行为,以防native_only失败。我的示例是针对Android进行测试的,而不是针对iOS。
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']);
}EDIT :我在how to use Facebook SDK in React Native上发表了一篇文章,其中我提到了更多内容(即如何执行图形请求)。如果你需要更多关于这个主题的信息,请查看它。
发布于 2019-01-15 18:49:54
我也有同样的困惑。我在FBSDK源代码中找到了相关信息。Andtoid和iOS有一个不同的列表。我最终使用了跨平台版本的@jeevium answer。
// something like this
LoginManager.setLoginBehavior(Platform.OS === 'ios' ? 'native' : 'NATIVE_ONLY');
/**
* Indicate how Facebook Login should be attempted on Android.
*/
export type LoginBehaviorAndroid =
// Attempt login in using the Facebook App, and if that does not work fall back to web dialog auth.
'native_with_fallback'|
// Only attempt to login using the Facebook App.
'native_only'|
// Only the web dialog auth should be used.
'web_only';
/**
* Indicate how Facebook Login should be attempted on iOS.
*/
export type LoginBehaviorIOS =
// Attempts log in through the native Facebook app.
// The SDK may still use Safari instead.
// See details in https://developers.facebook.com/blog/post/2015/10/29/Facebook-Login-iOS9/
'native' |
// Attempts log in through the Safari browser.
'browser' |
// Attempts log in through the Facebook account currently signed in through Settings.
'system_account' |
// Attempts log in through a modal UIWebView pop-up.
'web';https://stackoverflow.com/questions/39835006
复制相似问题