我使用react本机-fbsdk 0.4.0,并遵循https://github.com/facebook/react-native-fbsdk中的步骤。在添加本机FBSDK和FB登录按钮后,我尝试了本机Object测试应用程序,没有问题。
然而,我也遇到了与这个帖子React Native Facebook Login using official fbsdk相同的问题。
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View
} from 'react-native';
const FBSDK = require('react-native-fbsdk');
const {
LoginButton,
AccessToken
} = FBSDK;
var Login = React.createClass({
render: function() {
return (
<View>
<LoginButton
publishPermissions={["publish_actions"]}
onLoginFinished={
(error, result) => {
if (error) {
alert("login has error: " + result.error);
} else if (result.isCancelled) {
alert("login is cancelled.");
} else {
AccessToken.getCurrentAccessToken().then(
(data) => {
alert(data.accessToken.toString())
}
)
}
}
}
onLogoutFinished={() => alert("logout.")}/>
</View>
);
}
});
AppRegistry.registerComponent('fbsdk_rn', () => Login);真的很感谢你的帮助。谢谢。
更新:只是解决了我的问题,希望能激励其他人。我从https://github.com/magus/react-native-facebook-login上查看了这个“react原生-facebook-登录”。
整个过程几乎相同,只是"AppDelegate.m“中有一个不同的”头文件导入“
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h> 我添加了FBSDKLoginKit.h的第二个导入,它可以工作。
发布于 2019-07-08 14:49:12
--我正在使用这段代码--在我的例子中-- Login工作得很好,如果您可以使用这段代码,我确信您的按钮工作正常.
看这里的代码..。
<LoginButton
publishPermissions={["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)
}
}
}
onLogoutFinished={() => alert("User logged out")}
/>和App.js文件在这里
import React, { Component } from 'react';
import { View,StyleSheet } from 'react-native';
import { LoginButton, AccessToken, LoginManager, } from 'react-native-fbsdk';
import { ShareApi } from 'react-native-fbsdk';
export default class App extends Component {
componentDidNotMount() {
LoginManager.logInWithPermissions(['public_profile']).then(
function(result) {
if (result.isCancelled) {
alert('Login cancelled');
} else {
alert(
'Login success with permissions: ' +
result.grantedPermissions.toString()
);
}
},
function(error) {
alert('Login fail with error: ' + error);
}
);
}
render() {
return (
<View style={styles.container}>
<LoginButton
publishPermissions={["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)
}
}
}
onLogoutFinished={() => alert("User logged out")}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});https://stackoverflow.com/questions/41435499
复制相似问题