2013-03-28 40 views
2

我一直在努力获得一个Facebook的“张贴到墙”对话,以显示在我的网站上,但它显示的是所有页面上的代码。Facebook Feed对话显示代码而不是内容

这是应该发生的事情:

  1. 访问者来到我的网站,点击定制的“分享”按钮,我做了
  2. 的访问者然后将其重定向到饲料对话框在不同的页面和他们分享我的网页。
  3. 然后他们继续下载我提供的东西。

我犯了一个Facebook应用程序,然后从Facebook开发人员网页复制的代码,并填写了我需要的一切,但只要我点击它把我的份额达到了页面的所有代码来代替。

enter image description here

+1

你有现在10个代表:) – jrummell

+0

非常感谢。 – user2221218

回答

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> 
+0

我从来没有编码过。我用常识来编码所有东西,所以我仍然对你说的有问题。我是否将两个脚本都保存在一个文件中,以及哪个扩展名应该将其另存为?我计划将其命名并将其放入我的主机帐户中的另一个文件夹中。非常有帮助 – user2221218

+1

您不需要创建任何js文件,只需将它放在HTML代码的中间,第一个脚本将它放在标记后面,不要忘记在

之后放置这个,另一个只是把它放在你的文件的底部 –

+0

非常感谢。 – user2221218

相关问题