Facebook login with javascript sdk


#1

I want to use the Facebook javascript sdk inside of the of ionic (not openFb or anyother plugib, but straight javscript sdk). Inside of my index page I added the sample javscript sdk Facebook provides for login. When I serve the app locally on my browser it works, but when I try to test it on a device I get a blank page and looking at the console I notice this error message:

Failed to load resource: net::ERR_FILE_NOT_FOUND file://connect.facebook.net/en_US/sdk.js

Has anyone got javascript sdk from Facebook to work on a device?


#2

The problem…
i think you have included the facebook sdk in that way_

<script .... src="//......"></script>

without http or https in front of the url to the sdk.
Desktop-browsers automatically detect you context (if it is http or https).

On mobile the default behavior in an app-context is “file” because the app thinks the file is served somewhere locally.

So solution:
add http or https in front of you script-src.


#3

Thanks for the reply. The part of the javscript sdk which calls this looks like this:

(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = “//connect.facebook.net/en_US/sdk.js”;
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));

I then changed it to:

(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = “http://connect.facebook.net/en_US/sdk.js”; (also tried https)
fjs.parentNode.insertBefore(js, fjs);
}(document, ‘script’, ‘facebook-jssdk’));

This though did not work, the same error occurs.


#4

Maybe you can build a little codepen?