An error occurred while trying to log in to Facebook - No solution

Please provide the following:

  1. SDK Version: “expo”: “^42.0.3”, - “expo-facebook”: “~11.3.1”
  2. Platforms(Android/iOS/web/all): Android
  3. Add the appropriate “Tag” based on what Expo library you have a question on.

Hello!

I am having problems with the facebook login. I have followed step by step the guide about expo-facebook. I have tested a lot of different solutions but the error: “An error occurred while trying to log in to Facebook”, continues.

Hope some of you can help me.

My app.json

{
  "expo": {
    "name": "Prestadores",
    "slug": Prestadores",
    "version": "1.0.0",
    "orientation": "portrait",
    "userInterfaceStyle": "automatic",
    "icon": "./assets/123.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "facebookAutoInitEnabled": true,
    "facebookAppId": "123123",
    "facebookDisplayName": "NAME",
    "facebookScheme": "fb123123",
    "notification": {
      "icon": "./assets/123.png",
      "color": "#FFA73F",
      "androidMode": "default",
      "androidCollapsedTitle": "Updates from Fuwu",
      "iosDisplayInForeground": true
    }
  }
}

The error is only in android, because for iOS it is working properly.

My code:

  let promise = new Promise(async (resolve,reject)=>{

    try {
       await Facebook.initializeAsync({
          appId: '123123123', appName:'NAME'
        });
        
         await Facebook.logInWithReadPermissionsAsync({
          permissions: ['public_profile','email'],
        });
          console.log('paso de login', res);
          if (type == 'success') {
            // Get the user's name using Facebook's Graph API
            const response = await fetch(`https://graph.facebook.com/v11.0/me?access_token=${token}&fields=email,id,name,picture.type(large)`);
            resolve(await response.json())
          } else {
            reject('error')
          }
        
      
      } catch (error) {
        console.log('message error', error);
        resolve(`Facebook Login Error: ${error.message}`);
      }
    
   }) 
   
    return await promise

Hey @jackdmarquez, could you try diving into the native device logs? They often will provide much more insight and more descriptive/specific errors.

Cheers,
Adam

1 Like

Hey @jackdmarquez

This seems to be an issue with the native Facebook login flow. Changing the ‘behavior’ option to ‘browser’ in logInWithReadPermissionsAsync as per below seemed to work for me.

await Facebook.logInWithReadPermissionsAsync({
        permissions: ["public_profile", "email"],
        behavior: "browser"
});

Cheers
Neall

2 Likes

Bro, I dont know about you… but you saved me after spending 2h trying to make it work…

Yes, is not the perfect solution but better them not having it.

Thanks brother it worked after 2 months with this problem

1 Like

Thank you man!! You saved me!

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.