facebook login with react native Error Cannot read property 'logInWithReadPermissions' of undefined

1.7k views Asked by At

I am using react-native-fbsdk for login in react-native app. after all setup , I am getting some error.

code I used for login action

facebook = () => {
     console.log("LoginManager ", LoginManager);
    console.log("Login  ", LoginManager.logInWithReadPermissions);

    LoginManager.logInWithReadPermissions([
      "public_profile"
    ]).then(result => {
      if (result.isCancelled) {
        console.log("Login cancelled");
      } else {
        console.log(
          "Login success with permissions",
          result.grantedPermissions.toString()
        );
      }
    });
  };

now here is my console output 1 :

LoginManager  
Object {logInWithReadPermissions: function, logInWithPublishPermissions: function, getLoginBehavior: function, setLoginBehavior: function, getDefaultAudience: function…}
getDefaultAudience
:
function getDefaultAudience()
getLoginBehavior
:
function getLoginBehavior()
logInWithPublishPermissions
:
function logInWithPublishPermissions(permissions)
logInWithReadPermissions
:
function logInWithReadPermissions(permissions)
logOut
:
function logOut()
setDefaultAudience
:
function setDefaultAudience(defaultAudience)
setLoginBehavior
:
function setLoginBehavior(loginBehavior)

now here is my console output 2 :

function logInWithReadPermissions(permissions) {
    return LoginManager.logInWithReadPermissions(permissions);
  }

Error : Cannot read property 'logInWithReadPermissions' of undefined what is missing here not able to get .

enter image description here

3

There are 3 answers

0
Fabian Stevens Varon Valencia On

might you can follow this video tutorial about iOs + Facebook Configuration.

Also you can review the command react-native link to link well the FBSDK libraries.

Hope that my answer helps you.

0
Robin Tang On

Are you using Android or iOS? Chances are that you haven't properly linked the Facebook SDK for the mobile platform that you're using.

For Android you should ensure that you have completed all the steps in the quickstart here: https://developers.facebook.com/quickstarts/?platform=android

For iOS, check through the Troubleshooting section here: https://developers.facebook.com/docs/react-native/configure-ios You might actually find an error in your logs during the compile phase or when your app has just started running.

0
Kebab Krabby On

Iam little bit late to the party but use loginWithPermissions instead.

the other two methods are deprecated (loginWithReadPermissions, loginWithPublishPermissions)

for in instance:

var result = await LoginManager.logInWithPermissions(scope)

with fbsdk version:

"react-native-fbsdk": "1.0.1"

dont forget to run yarn install if you change versions in package.json