Unable to fetch user using Facebook js sdk v2.10 on Firefox

123 Views Asked by At

I am trying to add facebook authentication on our website using Facebook Javascript SDK v2.10. My aim is to login via Facebook and then fetch the user which was authenticated. The problem I am facing is that on Firefox, I am unable to fetch the authenticated user.

I have created a test page HERE

When you click on the button 'Login via Facebook', the FB.login function is called. When the response is received, I am calling the FB.api function. Following is my code

FB.login(function(response) {
              let p1 = document.createElement('p');
              p1.innerHTML = "FB.login response follows:<br>"+ JSON.stringify(response);
              document.body.appendChild(p1)
              FB.api('/me', {fields: 'id,first_name'},
                  function(response) {
                      let p2 = document.createElement('p');
                      p2.innerHTML = "FB.api response follows:<br>"+ JSON.stringify(response);
                      document.body.appendChild(p2)
                  });
          });

In Chrome,the callback of FB.api is called and the response is received,but, in Firefox, this is not happening. Kindly help me figure out why this is happening

1

There are 1 best solutions below

0
On BEST ANSWER

Ok. I was using Facebook sdk in Polymer app. The sdk documentation suggests adding the sdk initialization code in index.html.

But, for Polymer, you need to add the code in the connectedCallback method of your root app (my-app.html if you are using polymer-starter-kit)

For reasons unknown, the webcomponent-loader.js blocks Facebook initialization on Firefox, if sdk code is added in index.html.