Ausgabe
Ich versuche, das erste Beispiel aus der Dokumentation des Facebook JS SDK auszuführen. Ich habe eine neue App erstellt, ein leeres Dokument namens „facebookTest.html“ erstellt, den Code aus dem Beispiel eingefügt und die App-ID der neuen App eingefügt. Codieren Sie wie folgt:
<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>
Wenn ich die Seite lade, erhalte ich in der Javascript-Konsole folgende Fehlermeldung:
Failed to load resource
Was mache ich falsch?
BEARBEITEN: Wenn ich document.location.protocol
vor dem "//connect.facebook.net/..."
, wie hier vorgeschlagen, hinzufüge , bleibt der Bildschirm leer und die Konsole zeigt Folgendes:
GET file://connect.facebook.net/en_US/all.js
Ist das alles, was dieser Code tun soll? Oder schlägt es immer noch fehl?
Lösung
Hier waren ein paar Dinge falsch:
-
erforderlich, um die
js.src
Zuordnung zu ändern:
js.src="https://connect.facebook.net/en_US/all.js";
-
Facebook unterstützt JS SDK-Aufrufe aus einer lokalen Datei nicht mehr, das Skript muss gemäß diesem Fehlerbericht auf Facebook
http://
auf einer Datei mit einem oder -URI ausgeführt werden . Ich muss die Datei auf einen Webserver hochladen, die Leinwand-URL entsprechend ändern und erneut testen.https://
Beantwortet von – Siegel
Antwort geprüft von – Jay B. (FixError Admin)