I'm currently implementing a Facebook login button into my react native application. Once the user logged in successfully I grab some information, firstname, lastname and email address.
After reading the SDK documentation and online examples I can see two different approaches to achieve this:
Using LoginButton & AccessToken then do a GraphRequest
Using LoginManager then do a GraphRequest (the approach I chose):
class LoginView extends Component { _fbAuth = () => { LoginManager.logInWithReadPermissions(['public_profile','email']).then(function(result){ if(result.isCancelled){ console.log('loging cancelled') } else { console.log('login success' + result.grantedPermissions) const infoRequest = new GraphRequest('/me', { parameters: { 'fields': { 'string' : 'email,first_name,last_name,picture' } } }, (err, res) => { console.log(err, res); }); new GraphRequestManager().addRequest(infoRequest).start(); } }, function(error){ console.log('An error occured: ' + error) }) } render(){ return ( <TouchableHighlight style={{flex:1}} onPress={() => {this._fbAuth()}}> <View style={styles.container}> <View style={styles.buttonContainer}> <Text style={{flex:1}}>Login with Facebook</Text> </View> </View> </TouchableHighlight> ) } }
What is the main difference between LoginManager & LoginButton?
Online examples of LoginButton also get the current token: AccessToken.getCurrentAccessToken().then(...)
With LoginManager I managed to get the user information without having to use AccessToken - is LoginManager calling AccessToken behind the scene?
Is there a preferred approach?