FB.UI对话框未出现在django应用程序中

时间:2017-10-26 09:20:00

标签: javascript facebook facebook-graph-api facebook-javascript-sdk

我正在尝试这个在Facebook上分享帖子:

<div id="shareBtn" class="btn btn-success clearfix">Share Dialog</div>

<p>The Share Dialog enables you to share links to a person's profile without them having to use Facebook Login. <a href="https://developers.facebook.com/docs/sharing/reference/share-dialog">Read our Share Dialog guide</a> to learn more about how it works.</p>

<script>
document.getElementById('shareBtn').onclick = function() {
  FB.ui({
    display: 'popup',
    method: 'share',
    href: 'https://developers.facebook.com/docs/',
  }, function(response){});
}
</script>

我想知道由于我的应用程序未获得共享对话框而遗漏了什么。

以下是我发现的控制台错误:

(index):292 Uncaught ReferenceError: FB is not defined
    at HTMLDivElement.document.getElementById.onclick ((index):292)

1 个答案:

答案 0 :(得分:0)

您必须加载JavaScript SDK:

window.fbAsyncInit = function() {
    //SDK loaded, initialize it
    FB.init({
        appId      : 'your-app-id',
        xfbml      : true,
        version    : 'v2.10'
    });

    //now FB is available
};

//load the JavaScript SDK
(function(d, s, id){
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) {return;}
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.com/en_US/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));

更多信息: