user3801462
user3801462

Reputation: 13

Facebook app built in JavaScript SDK not posting to Timeline

I've developed a Facebook app / standalone website that uses a custom object and action to support the University of Leeds open days. This is built using the JavaScript SDK.

Here is the URL - https://fbapps.leeds.ac.uk/opendays/recap.html

The code works fine and posts to Open Graph, but only posts to that user's profile and doesn't appear on the Timeline.

Facebook have approved my request for explicit sharing and this is enabled in the app settings, however it still doesn't seem to post to a user Timeline as I would expect.

The post does show up in Activity Log though.

I've added the explict sharing parameter to the code, changed the default privacy settings and enabled publish_actions in the data_scope.

Does anyone have any idea what's missing please, as can't see to figure out the issue?

Any advice gratefully received. Many thanks for any help anyone can provide on this.

Here's the code:

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

Upvotes: 1

Views: 977

Answers (1)

Sahil Mittal
Sahil Mittal

Reputation: 20753

Well that's the good thing of the Open Graph :D

The Open Graph Stories are not posted as the status, it's an activity that user has performed using your app. So, these stories are bundled together as the app activities rather than posting a status on timeline and unnecessarily flooding the timeline.

So, in your timeline check for the Recent Activity section (scroll down a bit, you'll find that)-

enter image description here

But don't worry this story is shared in a proper big block on your and your friend's wall (whatever privacy setting you've set). To check out how will this story look like on the wall you can check your wall itself, but if you're not able to find it (there are n number of wall posts, could be difficult to find one)-

  • click on the time, yellow marked in the above screenshot, or
  • go to the Activity Log and click on the time-

    enter image description here


And here's how the post will look like-

enter image description here

Upvotes: 2

Related Questions