Facebook Feed Dialogue显示代码而不是内容

时间:2013-03-28 19:52:58

标签: facebook

我一直在努力想要在我的网站上显示一个facebook“post to wall”对话,但所有显示的都是该页面上的代码。

以下是应该发生的事情:

  1. 访问者访问我的网站并点击我制作的自定义“分享”按钮
  2. 然后,访问者会将其重定向到其他页面上的Feed对话框,然后他们会共享我的页面。
  3. 然后他们继续下载我提供的内容。
  4. 我制作了一个Facebook应用程序,然后从Facebook开发者页面复制了代码,并填写了我需要的所有内容,但无论何时我点击共享,它都会带我到一个包含所有代码的页面。

    enter image description here

1 个答案:

答案 0 :(得分:1)

试试这个,加载javascript SDK:

<div id="fb-root"></div>
    <script>
        window.fbAsyncInit = function() {
            FB.init({
              appId      : 'YOUR_APP_ID', // App ID
              channelUrl : 'URL_TO_CHANNEL_FILE', // Channel File optional
              status     : true, // check login status
              cookie     : true, // enable cookies to allow the server to access the session
              xfbml      : true  // parse XFBML
            });
        };

        // 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);
        }(document));
    </script>

然后为您的按钮添加一个监听器,假设您的按钮具有ID,bt-download

<script>    
$(document).on("click", "#bt-download", function(){
       var obj = {
            method: 'feed',
            link: 'link to your webpage',
            picture: "url to the picture you want size 90px x 90px",
            name: 'the name you want',
            caption: 'your caption',
            description: 'your description',
            display: 'popup'
       };

       function callback(response) {
           if (response && response.post_id) {
            alert('Post was published.');
            //here you can redirect the user to the download page
           } else {
             alert('Post was not published.');
           }
       }
       FB.ui(obj, callback);

            });
</script>
相关问题