Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
132
rated 0 times [  135] [ 3]  / answers: 1 / hits: 67796  / 11 Years ago, wed, march 27, 2013, 12:00:00

I'm trying to run the first example from the documentation of the Facebook JS SDK. I created a new app, created a blank document called facebookTest.html, pasted in the code from the example, and plugged in the new app's App ID. Code as follows:



<html>
<head>
<title>Login with facebook</title>
<div id=fb-root></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'my app ID', // App ID from the App Dashboard
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});

// Additional initialization code such as adding Event Listeners goes here

};

// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = document.location.protocol+//connect.facebook.net/en_US/all + (debug ? /debug : ) + .js;
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
</script>


When I load the page, on the Javascript console I get the following error message:



Failed to load resource



What am I doing wrong?



EDIT: When I add document.location.protocol before the //connect.facebook.net/..., as suggested here, the screen stays blank, and the console shows the following:



GET file://connect.facebook.net/en_US/all.js  


Is that all this code is supposed to do? Or is it still failing?


More From » facebook

 Answers
12

There were a couple things wrong here:




  1. needed to change js.src assignment to:
    js.src=https://connect.facebook.net/en_US/all.js;


  2. Facebook no longer supports JS SDK calls made from a local file, the script has to be run on a file with an http:// or https:// URI, as per this bug report on Facebook. I will need to upload the file to a web server, change the canvas URL accordingly, and retest.



[#79290] Wednesday, March 27, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mackenzihannal

Total Points: 548
Total Questions: 96
Total Answers: 96

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;