capacitor-community / facebook-login

Facebook Login support
MIT License
103 stars 52 forks source link

Get email using Vue #65

Closed sbellver closed 2 years ago

sbellver commented 2 years ago

I'm using Quasar App (Vue) with Capacitor.

First, import the plugin:

import { Plugins } from '../../../src-capacitor/node_modules/@capacitor/core'; import '../../../src-capacitor/node_modules/@capacitor-community/facebook-login';

Then I can get login from fb:

const FACEBOOK_PERMISSIONS = ['email']; const result = await Plugins.FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS })

This works fine (I get client_id, token, etc), but I can't get the email field.

Then, I want to use getProfile function to get it, but

const result = await FacebookLogin.getProfile<{ email: string; }>({ fields: ['email'] });

is Typescript, not Vue.

If I change it to

const resultProfile = Plugins.FacebookLogin.getProfile({ fields: ['email'] });

i have an error: Facebook user's email is undefined

Any way to get email field without typescript?

rdlabo commented 2 years ago

Do you use recent plugin and capacitor?Plugins object is deprecated. Please check version. Thanks.

sbellver commented 2 years ago

I'm on Capacitor 2 (2.5, I think) & v2.0.0 If I use Capacitor 3 some code (not about fb login) don't work

rdlabo commented 2 years ago

Facebook SDK using from capacitor-community/facebook-login@2 is deprecated. I recommend to use recent version, and to resolve why some code don't work.

related: https://github.com/capacitor-community/facebook-login/issues/63 https://github.com/capacitor-community/facebook-login/issues/57

Thanks.

sbellver commented 2 years ago

Ok, thanks!

sbellver commented 2 years ago

I updated to Capacitor 3.2.2, and capacitor-community/facebook-login 3.1.1 I need to update my Podfile to platform :ios, '12.0' (instead 11, if it can help to someone)

But I have an undefined result 👍 `const resultProfile = FacebookLogin.getProfile({ fields: ['email'] });

      console.log(`Facebook user's email is ${resultProfile.email}`);
      console.log(resultProfile);`

But in Xcode debug I see my user email!!!

TO JS: {"email:"user@domain.com", "id":"1002030220"}

But, resultProfile.email is undefined. And I can't see resultProfile content (object).

Where is the email stored???

sbellver commented 2 years ago

I have it:

const result = await FacebookLogin.getCurrentAccessToken(); if (result.accessToken) { const resultLogin = await FacebookLogin.getProfile({ fields: ['email'] }); console.log(Facebook user's email is ${resultLogin.email}); }

sbellver commented 2 years ago

I want to share my code, if it helps someone.

` async loginFacebookApp() { await FacebookLogin.logout(); const FACEBOOK_PERMISSIONS = ['email'];

  try {
    console.log('Entramos en try');
    await FacebookLogin.login({ permissions: FACEBOOK_PERMISSIONS }).then(
      (res) => {
        console.log(res);
        FacebookLogin.getProfile({ fields: ['email'] }).then(
          (token) => {
            this.$api.post('social_login', token).then(({ data }) => {
              //Add API info
              this.$router.push({ name: 'home' });
            }).catch((error) => {
              this.$router.push({ name: 'signup', params: token });
              console.log(error);
            });
          },
        );
      },
    );
  } catch (error) {
    console.log(error);
  }
},

`