问题
I am having trouble with my ability to get the AccessToken in the fbsdk
in React Native.
I am calling the core as suggested by Facebook:
const FBSDKCore = require('react-native-fbsdkcore');
const {
FBSDKAccessToken,
} = FBSDKCore;
And in one scenario I try to write the token in the log as suggested by a similair question stated here on SO.
<View>
<View style={{flex: 1, alignItems: 'center', padding: 50, marginTop: 250}}>
<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 {
FBSDKAccessToken.getCurrentAccessToken((token)=> {
console.log(token);
});
Actions.Navigator()
}
}
}
onLogoutFinished={() => {
alert("logout.")}}/>
</View>
</View>
</View>
This gives me the redscreen "undefined is not an object (evaluating the FBSDKAccessTokenInterface.getCurrentAccessToken)
Trying to pull off something similair in other parts of the app, of course defining the const FBSDKAccessToken
first, then calling the userID
(which should be a part of the FBSDKCore
) as:
<Text style={{fontSize: 18, color:colors.General.navtext}}>{FBSDKAccessToken.userID}</Text>
Yields nothing, where I believed it to return the userID of the logged in user. Also, if I try to write out the accesstoken in that same place as:
<Text style={{fontSize: 18, color:colors.General.navtext}}>{FBSDKAccessToken.getCurrentAccessToken()}</Text>
I get the same red screen as before.
I tried to look in to the linking of libraries, but that even caused further problem.
Hence, from this, I am pretty stranded and I would really appreciate some feedback on what has gone wrong.
回答1:
Try this.
console.log(token.accessToken.toString());
来源:https://stackoverflow.com/questions/37029783/issues-with-the-accesstoken-in-the-react-native-fbsdk