I've gotten facebook login working using the new https://github.com/facebook/react-native-fbsdk, however I can't seem to get the user token which is usually returned in the response. Anyone found a way to get this information? The other SDK's https://github.com/magus/react-native-facebook-login returns it on the login request but the new FB sdk doesn't, and the documentation on the github page doesn't mention it anywhere.
Getting user app token using react-native facebook SDK
Asked Answered
Can you share example code how you got it working? I am getting this problem: github.com/facebook/react-native-fbsdk/issues/10 –
Freese
Found the answer after some more digging. You need to use the fbsdkcore to access the user token. Heres how you use it.
var FBSDKCore = require('react-native-fbsdkcore');
var {
FBSDKAccessToken,
} = FBSDKCore;
var Login = React.createClass({
render: function() {
return (
<View>
<FBSDKLoginButton
onLoginFinished={(error, result) => {
if (error) {
alert('Error logging in.');
} else {
if (result.isCanceled) {
alert('Login cancelled.');
} else {
FBSDKAccessToken.getCurrentAccessToken((token) => {
console.log(token.tokenString);
})
}
}
}}
onLogoutFinished={() => console.log('Logged out.')}
readPermissions={[]}
publishPermissions={['publish_actions']}/>
</View>
);
}
});
In react-native-fbsdk version 0.3.0 this is no longer FBSDKAccessToken but instead AccessToken. –
Ceballos
I have one question. I need email permission. how should I write.
readPermissions={['public_profile', 'email']}
¿Is it okay? –
Cenobite I was trying to get console.log(JSON.stringify(result)); But I didn't get any result on login with facebook click –
Zen
You don't need a third party module (react-native-fbsdkcore
)
The package (react-native-fbsdk
) has instructions on it's Github page: https://github.com/facebook/react-native-fbsdk#usage
After you've logged the user in, you can fetch the access credentials as follows:
import { AccessToken } from 'react-native-fbsdk';
AccessToken.getCurrentAccessToken().then(data => {
console.log(data.accessToken.toString())
})
© 2022 - 2024 — McMap. All rights reserved.