Javascript facebook connect登录(JS SDK)更麻烦

Javascript facebook connect登录(JS SDK)更麻烦,javascript,jquery,facebook-graph-api,Javascript,Jquery,Facebook Graph Api,我真的一点也不明白。我的目标是在我的主aspx文件中没有一堆js。我想要一个外部文件。我就是不能让它工作 下面的内容似乎在登录弹出窗口中起作用,但它从不更新来宾内容,并且登录按钮停留在那里。控制台说FB没有定义,所以很明显它不知道FB.api意味着什么。。。对不起,我在这方面很差劲:| [---index.aspx-------] 您可以在window.fbasyninit处理程序中调用FB.init,这很好,这样在加载所有FB内容之前,它不会被执行。但是您在处理程序之外调用了FB.api,这意

我真的一点也不明白。我的目标是在我的主aspx文件中没有一堆js。我想要一个外部文件。我就是不能让它工作

下面的内容似乎在登录弹出窗口中起作用,但它从不更新来宾内容,并且登录按钮停留在那里。控制台说FB没有定义,所以很明显它不知道FB.api意味着什么。。。对不起,我在这方面很差劲:|

[---index.aspx-------]


您可以在window.fbasyninit处理程序中调用FB.init,这很好,这样在加载所有FB内容之前,它不会被执行。但是您在处理程序之外调用了FB.api,这意味着您不能保证在调用FB.api之前所有的.js都已完成加载。最简单的解决方案是在警报发出后将FB.api块移动到window.fbasyninit函数中

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="index.aspx.vb" Inherits="MyGameEngineBeta.index" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://ogp.me/ns/fb#">
    <head runat="server">
        <title>Scott's Test</title>
        <script src="JS/jquery-1.6.4.min.js" type="text/javascript"></script>
    </head>
    <body>
        <div id="fb-root"></div>
        <script src="JS/facebook.js" type="text/javascript"></script>
        <fb:login-button show-faces="false" width="200" max-rows="1"></fb:login-button>
        <div>Welcome <span id="guest" class="UserNameWelcome">Guest</span><span id="name" class="UserNameWelcome"></span>!</div>
    </body>
    </html>
window.fbAsyncInit = function () {
    FB.init({
        appId: 'mysiteid', // App ID
        channelURL: '//www.mysite.net/channel.html', // Channel File
        status: true, // check login status
        cookie: true, // enable cookies to allow the server to access the session
        oauth: true, // enable OAuth 2.0
        xfbml: true  // parse XFBML
    });

    // Additional initialization code here
    alert('Facebook initialized');
};

// Load the SDK Asynchronously
(function (d) {
    var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
    js = d.createElement('script'); js.id = id; js.async = true;
    js.src = "//connect.facebook.net/en_US/all.js";
    d.getElementsByTagName('head')[0].appendChild(js);
} (document));

//update guest/username if logged in or not
FB.api('/me', function (user) {
    if (user != null) {
        alert('logged in');
        var name = document.getElementById('name');
        name.innerHTML = user.name
        $('#guest').hide();
    } else {
        alert('guest');
        $('#image').hide();
        $('#name').hide();
    }
});