正在尝试学习facebook API,但未调用window.fbAsyninit

正在尝试学习facebook API,但未调用window.fbAsyninit,facebook,api,Facebook,Api,我看了一下,但似乎没有找到答案……我的js文件中的window.fbAsyncint似乎没有被调用。这是一个让我熟悉API的测试应用程序,非常基本,这就是为什么PHP snippit出现在HTML部分;)。我的一个想法是JS看不到fb root DIV,所以我尝试在之后加载JS,甚至去掉了除了Facebook之外的所有内容,但仍然什么都没有……info DIV的innerHTML和控制台都没有显示任何内容。我确实在DIV和控制台中收到了“SDK已加载”消息,因此我知道API正在加载。我也没有收到

我看了一下,但似乎没有找到答案……我的js文件中的window.fbAsyncint似乎没有被调用。这是一个让我熟悉API的测试应用程序,非常基本,这就是为什么PHP snippit出现在HTML部分;)。我的一个想法是JS看不到fb root DIV,所以我尝试在之后加载JS,甚至去掉了除了Facebook之外的所有内容,但仍然什么都没有……info DIV的innerHTML和控制台都没有显示任何内容。我确实在DIV和控制台中收到了“SDK已加载”消息,因此我知道API正在加载。我也没有收到任何错误。有人知道为什么这不起作用吗?还尝试了FF、Chrome、Safari和IE(mac和pc),结果相同。

代码最初来自一个教程网站(稍作调整:),但我仔细检查了facebook文档,它和他拥有的完全相同

HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Guess Test</title>
    <link href="guess.css" rel="stylesheet" type="text/css">
    <script src="jquery-1.7.2.min.js" type="text/javascript"></script>
    <script src="guess.js" type="text/javascript"></script>
</head>
<body>
<div id="fb-root"></div>
<?php echo "Welcome to the guess test program :D<br>"; ?>

<div id="alertbox"></div>

<br>
<div>Enter your guess between 1 and 10: <input type=text id='myGuess' name='myGuess'>
<input type='button' onClick='Guess()' value='Guess'>
<br>
<br>
<input type='button' onClick='document.getElementById("alertbox").innerHTML = "reset"; Restart()' value='Start Again'>
<br>
<div id="info"><div>

<script type=text/javascript>Restart();</script>

</body>
</html>

猜测测验

输入介于1和10之间的猜测:


重启();
Javascript(js文件)…ID和URL已删除:)

var-iRandom;
var欺骗=错误;
var fb_login=“foo”;
fb_login=“开始”;
函数重新启动(){
document.getElementById(“info”).innerHTML=fb\u login;
iRandom=Math.floor(Math.random()*10)+1;
如果(作弊)
document.getElementById(“info”).innerHTML=iRandom;
var tempstring=document.getElementById(“alertbox”).innerHTML;
如果((tempstring==“”)| |(tempstring==“重置”)){
document.getElementById(“alertbox”).innerHTML=“好的,我想到的是一个介于1和10之间的数字”;
}
}
函数猜测(){
var yourGuess=document.getElementById('myGuess').value;
如果(yourGuess>iRandom){
document.getElementById(“alertbox”).innerHTML=“太高。”;
}
如果(你猜)
var iRandom;
var cheat=false;
var fb_login = "foo";
fb_login = "Start";

function Restart() {
    document.getElementById("info").innerHTML = fb_login;
    iRandom = Math.floor(Math.random()*10)+1;
    if(cheat)
        document.getElementById("info").innerHTML = iRandom;
    var tempstring = document.getElementById("alertbox").innerHTML;
    if((tempstring == "") || (tempstring == "reset")) {
        document.getElementById("alertbox").innerHTML = "OK, I am thinking of a number between 1 and 10";
        }
    }

function Guess() {
    var yourGuess = document.getElementById('myGuess').value;
    if (yourGuess>iRandom) {
        document.getElementById("alertbox").innerHTML = "Too High.";
        }
    if (yourGuess<iRandom) {
        document.getElementById("alertbox").innerHTML = "Too Low.";
        }
    if (yourGuess==iRandom) {
        document.getElementById("alertbox").innerHTML = "Well done! You guessed it.";
        Restart();
        }
    }

window.fbAsyncInit = function() {
    console.log("START FB init");
    fb_login = "START FB init";
    FB.init({
        appId      : 'USED-MY-APP-ID', // App ID
        channelUrl : '//MYURL.com/facebook/channel.php', // Channel File
        status     : true, // check login status
        cookie     : true, // enable cookies to allow the server to access the session
        xfbml      : true,  // parse XFBML
        frictionlessRequests : true // enable frictionless requests
        });

        // Additional initialization code here
    FB.getLoginStatus(function(response) {
        if (response.status === 'connected') {
            var uid = response.authResponse.userID;
            accessToken = response.authResponse.accessToken;
            fb_login = "Welcome back";
            alert("Welcome back");
            }
        else if (response.status === 'not_authorized') {
            //User is logged into Facebook, but not your App
            //LOG IN function
            fb_login = "App not authorized";
            alert("App not authorized");
            }
        else {
            // User is not logged into Facebook at all
            window.top.location ='https://www.facebook.com/index.php';
            fb_login = "no facebook";
            alert("no facebook");
            }
        });
    };

// Load the SDK Asynchronously
(function(d){
    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 = "//connect.facebook.net/en_US/all.js";
    ref.parentNode.insertBefore(js, ref);
    fb_login = "SDK loaded";
    console.log("SDK loaded");
    }(document));