python - Facebook 连接 django/python

标签 python django facebook

我已经坚持了一段时间。遵循谷歌教程时,我似乎无法让 Facebook 登录弹出:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
    FB.init({appId:'137101656332358', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('auth.sessionChange', function(response) {
        if (response.session) {
            // A user has logged in, and a new cookie has been save
        } else {
            // The user has logged out, and the cookie has been cleared
        }
    });

我在 Firebug 中收到以下错误:

Firebug cannot find _firebugConsole element true Window localhost:8000
Firebug cannot find _firebugConsole element true Window localhost:8000
Firebug cannot find _firebugConsole element true Window localhost:8000
FB is not defined
[Break on this error] FB.provide('',{getLoginStatus:function...ern:FB._inCanvas?0:2});return a;}}}); 

我设置 Site URL = http://localhost:8000/

谢谢!

最佳答案

新的 Facebook API 需要异步加载:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    //[here goes your code:]
    FB.init({appId:'137101656332358', status: true, cookie: true, xfbml: true});
    FB.Event.subscribe('auth.sessionChange', function(response) {
        if (response.session) {
        // A user has logged in, and a new cookie has been save
        } else {
        // The user has logged out, and the cookie has been cleared
        }
    });
  };
  (function() {
    var e = document.createElement('script'); e.async = true;
    e.src = document.location.protocol +
      '//connect.facebook.net/en_US/all.js';
    document.getElementById('fb-root').appendChild(e);
  }());
</script> 

关于python - Facebook 连接 django/python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3588785/

相关文章:

python - Numpy:检查值是否为 NaT

python - 使用 Javascript 将 Python 代码放入 HTML 文件中

django - 如何在基于类的 View 中拥有多个表单

javascript - 自动化: Typing into input field throws error

python - 使用 Flask 将表单中的输入行作为对象发布?

python - 计算两个事件之间有多少obs的算法

django - "name ' django ' not defined"使用通用登录 View 时出错?

css - Facebook 的 "virtual scrolling"是如何工作的?

ios - 如何打开 Facebook Messenger 并直接发送给某人?

Facebook 权限