我正在将react-native-fbsdk 0.8.0与React-Native 0.57.4结合使用,并得到错误:
登录失败,并显示错误:操作无法完成。 (com.facebook.sdk.login错误308)。
大约30%的时间。我已经尝试使用LoginButton和LoginManager。
还尝试了react-native-fbsdk的v0.9和v0.7,结果相同。
使用LoginManager,我也尝试了其他人(即https://medium.com/@crysfel/error-when-login-with-facebook-sdk-react-native-c06a33078102)发布的LoginManager.logOut()技巧
我已启用了钥匙串共享功能。
我已经按照https://github.com/facebook/react-native-fbsdk上的所有说明进行操作,包括设置LSApplicationQueriesSchemes
如果它能正常工作2/3次,那么我该如何尝试下一步的建议?
我的登录按钮代码:
<LoginButton
style={[styles.button, styles.facebook]}
readPermissions={[
'public_profile',
'user_birthday',
'user_gender',
'email'
]}
onLoginFinished={(error, result) => {
if (error) {
alert('Login failed with error: ' + error.message);
} else if (result.isCancelled) {
alert('Login was cancelled');
} else {
// alert(
// 'Login was successful with permissions: ' +
// result.grantedPermissions
// );
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString());
this.fetchProfile().then(profile =>
this.checkOrAddUser(profile)
);
});
}
}}
onLogoutFinished={() => alert('User logged out')}
/>
我的LoginManager代码:
handleLogin = () => {
LoginManager.logInWithReadPermissions([
'public_profile',
'user_birthday',
'user_gender',
'email'
]).then(
result => {
if (result.isCancelled) {
console.log(result);
console.log('Login cancelled');
} else {
console.log(
'Login success with permissions: ' +
result.grantedPermissions.toString()
);
console.log('result is ' + result);
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString());
this.fetchProfile().then(profile => this.checkOrAddUser(profile));
});
}
},
function(error) {
console.log(error);
console.log('Login fail with error: ' + error.message);
LoginManager.logOut();
alert('Login failed. Try again.');
}
);
};
答案 0 :(得分:0)
通过执行此线程末尾的步骤,我能够在iOS上解决此问题: https://github.com/facebook/facebook-swift-sdk/issues/286
即,将这些行添加到我的Podfile中
pod 'FacebookSDK', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKCoreKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKShareKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
pod 'FBSDKLoginKit', :git => 'https://github.com/facebook/facebook-objc-sdk.git', :branch => 'master'
并删除我手动添加到“使用库链接二进制文件”部分的FBSDK .framework文件,运行“ pod install”,然后清理构建和派生数据文件夹。
答案 1 :(得分:0)
希望这会有所帮助。
import React, { Component } from 'react';
import { View, Button } from 'react-native';
import { LoginButton, AccessToken } from 'react-native-fbsdk';
export default class Login extends Component {
render() {
return (
<View style={{flex: 1, flexDirection: 'column'}}>
<LoginButton
onLoginFinished={
(error, result) => {
if (error) {
console.log("login has error: " + result.error);
} else if (result.isCancelled) {
console.log("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
console.log(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => console.log("logout.")}/>
</View>
);
}
};