0

This is my code

this.facebook.login(['email', 'public_profile']).then((response: FacebookLoginResponse) => {
      this.facebook.api('me?fields=id,name,email,first_name,picture.width(720).height(720).as(picture_large)', [])
      .then((profile: any) => {
        let userData = {
          email: profile['email'],
          first_name: profile['first_name'],
          picture: profile['picture_large']['data']['url'],
          username: profile['name'],
          id: profile['id']
        }
        alert(userData);

In the emulators alert box, it's showing output as

[object object]

How can I resolve this issue?

1
  • use console.log() because you userData is a object Commented Oct 4, 2018 at 11:32

3 Answers 3

5

As your userData might be an JSON parsed object, it shows [object object].

Try using alert(JSON.stringify(userData)) and I guess it should solve your problem.

Also if you just want to verify the object data then you can use simply use console.log(userData).

Sign up to request clarification or add additional context in comments.

Comments

1

You need to use JSON.stringify when you are displaying on alert,

 alert(JSON.stringify(userData));

1 Comment

I want to assign the values to the userData. after converting into the string how can I read specific values like id,first_name,email etc & assign it to the userData variable.
0

use "console.log(userData);" instead of "alert(userData);"

  • alert() is blocking & cannot be easily suppressed in a non-debug environment
  • console typically formats your objects nicely and allows to traverse them

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.