Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native-fbsdk - how to get user profile?

onLoginFinished's result just tells me the granted permissions. From the repo, not clear how to get the user profile. Seems like react-native-fbsdkcore should wrap FBSDKProfile.h but don't see where it does.

 var FBSDKLogin = require('react-native-fbsdklogin');
    var {
      FBSDKLoginButton,
    } = FBSDKLogin;

    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 {
                    alert('Logged in.');
                  }
                }
              }}
              onLogoutFinished={() => alert('Logged out.')}
              readPermissions={[]}
              publishPermissions={['publish_actions']}/>
          </View>
        );
      }
    });
like image 205
user2827377 Avatar asked Aug 14 '15 00:08

user2827377


People also ask

How do I get current user in react?

Step 1 - Retrieving Current User Its response will be your current user's object ( Parse. User ) or null if there is no logged-in user currently. const getCurrentUser = async function (): Promise<Parse. User | null> { const currentUser: Parse.


2 Answers

Found out you can get logged in user's profile with Graph API.

// Create a graph request asking for user's profile
var fetchProfileRequest = new FBSDKGraphRequest((error, result) => {
  if (error) {
    alert('Error making request.');
  } else {
    // Data from request is in result
  }
}, '/me');
// Start the graph request.
fetchProfileRequest.start();
like image 71
user2827377 Avatar answered Sep 20 '22 11:09

user2827377


There is an easier way to do it. Rather than manually making the graph request yourself, 'react-native-fbsdkcore' package to get the data associated with the logged in user (if there is one)

var

 FBSDKCore = require('react-native-fbsdkcore');

var {
  FBSDKAccessToken,
} = FBSDKCore;

FBSDKAccessToken.getCurrentAccessToken((token) => {
  // token will be null if no user is logged in, 
  // or will contain the data associated with the logged in user
});

cphackm address is that in this issue #2

like image 30
Russell Maxfield Avatar answered Sep 18 '22 11:09

Russell Maxfield