【问题标题】:Facebook app built in JavaScript SDK not posting to Timeline内置 JavaScript SDK 的 Facebook 应用程序未发布到时间轴
【发布时间】:2014-08-24 13:38:58
【问题描述】:

我开发了一个 Facebook 应用程序/独立网站,它使用自定义对象和操作来支持利兹大学开放日。这是使用 JavaScript SDK 构建的。

这是网址 - https://fbapps.leeds.ac.uk/opendays/recap.html

代码工作正常并发布到 Open Graph,但仅发布到该用户的个人资料,不会出现在时间轴上。

Facebook 已经批准了我的明确分享请求,并且在应用设置中启用了此功能,但它似乎仍然没有像我预期的那样发布给用户时间线。

该帖子确实显示在活动日志中。

我已将显式共享参数添加到代码中,更改了默认隐私设置并在 data_scope 中启用了 publish_actions。

有没有人知道缺少什么,因为看不到问题?

感谢您的任何建议。非常感谢任何人对此提供的任何帮助。

代码如下:

<script type="text/javascript">
  // You probably don't want to use globals, but this is just example code
  var fbAppId = '1471972309703879';
  var objectToLike = 'https://fbapps.leeds.ac.uk/recap.html';

  /*
   * This is boilerplate code that is used to initialize
   * the Facebook JS SDK.  You would normally set your
   * App ID in this code.
   */

  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 1471972309703879, // App ID
      status     : true,    // check login status
      cookie     : true,    // enable cookies to allow the
                            // server to access the session
      xfbml      : true,     // parse page for xfbml or html5
                            // social plugins like login button below
      version    : 'v2.0',  // Specify an API version
    });

    // Put additional init code here
  };

  // Load the SDK Asynchronously
  (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.net/en_US/sdk.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));

  /*
   * This function makes a call to the og.likes API.  The
   * object argument is the object you like.  Other types
   * of APIs may take other arguments. (i.e. the book.reads
   * API takes a book= argument.)
   *
   * Because it's a sample, it also sets the privacy
   * parameter so that it will create a story that only you
   * can see.  Remove the privacy parameter and the story
   * will be visible to whatever the default privacy was when
   * you added the app.
   *
   * Also note that you can view any story with the id, as
   * demonstrated with the code below.
   *
   * APIs used in postLike():
   * Call the Graph API from JS:
   *   https://developers.facebook.com/docs/reference/javascript/FB.api
   * The Open Graph og.likes API:
   *   https://developers.facebook.com/docs/reference/opengraph/action-type/og.likes
   * Privacy argument:
   *   https://developers.facebook.com/docs/reference/api/privacy-parameter
   */

  function postLike() {
    FB.api(
       'me/leedsopendaypics:enjoy',
       'post',
       { recap: "https://fbapps.leeds.ac.uk/opendays/recap.html",
         fb:explicitly_shared = "true",
         privacy: {'value': 'EVERYONE'} },
       function(response) {
         if (!response) {
           alert('Error occurred.');
         } else if (response.error) {
           document.getElementById('result').innerHTML =
             '<h3>Please log in to Facebook above so you can share this page</h3>';
         } else {
           document.getElementById('result').innerHTML =
             '<a href=\"https://www.facebook.com/me/activity/' +
             response.id + '\" target="_parent">' +
             '<h3>Thanks. That has now been shared.</h3></a>';
         }
       }
    );
  }
</script>

<!--
  Login Button

  https://developers.facebook.com/docs/reference/plugins/login

  This example needs the 'publish_actions' permission in
  order to publish an action.  The scope parameter below
  is what prompts the user for that permission.
-->

<div
  class="fb-login-button"
  data-show-faces="true"
  data-width="200"
  data-max-rows="1"
  data-scope="publish_actions"
  return_scopes="true">
</div>

<div>
<input
  type="button"
  class="button"
  value="Share this recap page on your Facebook Timeline"
  onclick="postLike();">
</div>

<div id="result"></div>

【问题讨论】:

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


    【解决方案1】:

    这就是 Open Graph 的好处:D

    Open Graph Stories 不是作为状态发布的,它是用户使用您的应用执行的一项活动。因此,这些故事作为应用活动捆绑在一起,而不是在时间线上发布状态并不必要地淹没时间线。

    因此,在您的时间线中检查 最近的活动 部分(向下滚动一点,您会发现)-

    但不要担心这个故事会在您和您朋友的(无论您设置什么隐私设置)上的一个适当的大块中分享。要查看这个故事在墙上的样子,你可以检查你的墙本身,但如果你找不到它(墙上有 n 个帖子,可能很难找到)-

    • 点击上面截图中黄色标记的时间,或者
    • 进入活动日志并点击时间-


    下面是帖子的样子-

    【讨论】:

    • 非常感谢萨希尔。这真的很有帮助。阅读大量文档,您的解释最有意义。 :-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2011-05-21
    • 2012-03-20
    相关资源
    最近更新 更多