javascript - Facebook 方法 : Feed - JavaScript - Body OnLoad

标签 javascript facebook facebook-graph-api

首先:我不是英国人,我的英语也不是很好,那么抱歉。 我的 FB 应用程序出现问题。

这是代码:

//My Script
<script src="http://connect.facebook.net/en_US/all.js"></script>
<p><a onload="postToFeed(); return false;"> </a></p>

<p id="msg"></p>

<script>
  FB.init({appId: "********", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: "feed",
      link: "http://apps.facebook.com/bachflower/",
      picture: "http://glacial-hollows-5787.herokuapp.com/images/37p.png",
      name: "Wild Rose - Rosa Canina",
      caption: " ",
      description: "Dona: Decisione, motivazione, accettazione con gioia del quotidiano. Chi ne ha bisogno tende a pensare: Non vale la pena… meglio rinunciare. Non serve a nulla… - App by medicinanaturale.pro"
    };

    function callback(response) {

    }

    FB.ui(obj, callback);
  }

</script>

//This is my body OnLoad
<body text="#000000" onLoad="postToFeed();" >

问题是: 有些人可以在他们的墙上看到并正确分享 postToFeed 通知。 有些人看不到 postToFeed 的任何内容。 为什么?

有人可以帮助我吗?

比你, 安德里亚

最佳答案

postToFeed() 函数可能会在 FB 加载和初始化之前调用。 使用异步加载,如下所示:

<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
    // init the FB JS SDK
        FB.init({
           appId      : 'YOUR_APP_ID', // App ID from the App Dashboard
           channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File for x-domain communication
           status     : true, // check the login status upon init?
           cookie     : true, // set sessions cookies to allow your server to access the session?
           xfbml      : true  // parse XFBML tags on this page?
        });

        postToFeed();

    };

  // Load the SDK's source Asynchronously
    (function(d, debug){
       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" + (debug ? "/debug" : "") + ".js";
       ref.parentNode.insertBefore(js, ref);
    }(document, /*debug*/ false));
</script>

请参见此处:http://developers.facebook.com/docs/reference/javascript/

关于javascript - Facebook 方法 : Feed - JavaScript - Body OnLoad,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13342750/

相关文章:

javascript - 字符串中的第一个和最后一个数字?

javascript - 使用 Busboy 迁移 Express 应用程序中的 bodyParser()?

javascript - Facebook API 阻止用户搜索

Facebook 事件封面(图形 API)

objective-c - Facebook 图表 API : audio share

javascript - 根据div可见性jquery显示或隐藏按钮

javascript - 尝试在 OL map 上覆盖 geotiff 文件及其显示错误

facebook - 如何使用 Facebook API 发表评论

php - Facebook 图谱 API RSS 源

android - Developer.facebook.com 要求提供数据删除网址