【问题标题】:Facebook Feed Dialogue showing code instead of contentFacebook Feed Dialogue 显示代码而不是内容
【发布时间】:2013-12-08 11:37:06
【问题描述】:

我一直在努力在我的网站上显示一个 facebook“贴到墙上”对话,但它显示的只是该页面上的代码。

这是应该发生的事情:

  1. 一位访问者来到我的网站并点击了我制作的自定义“分享”按钮
  2. 然后访问者被重定向到不同页面上的提要对话框,他们共享我的页面。
  3. 然后他们继续下载我提供的内容。

我制作了一个 facebook 应用程序,然后从 facebook 开发者页面复制代码并填写了我需要的所有内容,但是每当我单击共享时,它会将我带到一个包含所有代码的页面。

【问题讨论】:

  • 你现在有 10 个代表 :)

标签: facebook


【解决方案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>

【讨论】:

  • 我以前从未编码过。我使用常识对所有内容进行编码,所以我仍然对您所说的内容有疑问。我是否将两个脚本保存在一个文件中,应该将其保存为什么扩展名?我计划将其命名为 index 并将其放在我的托管帐户中的另一个文件夹中。不过谢谢,非常有帮助
  • 你不需要创建任何js文件只要把它放在你的HTML代码中间,第一个脚本把它放在标签之后,别忘了把它放在后面
    ,另一个只是放在文件的底部
  • 你能说得更具体点吗?什么不起作用?您的控制台是否有任何错误(使用 firebug 或 google chrome 开发人员工具)
  • 没有错误。它无动于衷。当我测试它时它什么都不做。还是同一个页面。如果您有时间想要,可以在 Skype 上添加我,我会实时向您展示,这样可能会更清晰。
  • 可以,但一定要快
猜你喜欢
  • 1970-01-01
  • 2014-04-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多