How to publish stories on Facebook?

627 views Asked by At

I'm trying to achieve something like this, that will say something like 'X is playing a game on Y'.

enter image description here

I have been working at this for many hours but nothing I produce gives this result. I've searched through Google and other stackoverflow threads, but have found nothing. Here's the code that I already have:

<script>
function publishStory() {

  body = {
       name: "<?php echo $userInfo['name']; ?> is playing <?php echo $game['name']; ?>",
       link: "http://localhost",
       caption: "I'm playing <?php echo $game['name']; ?> at http://localhost/",
       message: "Wow! <?php echo $game['name']; ?> is amazing! Come play!",
       source: 'http://localhost/static/flash.swf',
       image: 'http://google.com/images/logo.gif',
       "actions": [{"name":"Play <?php echo $game['name']; ?> now at Localhost","link":"localhost"}],
       description: "The fascinating, compelling description"
     }

FB.api('/me/feed', 'post', body, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Published to stream - you might want to delete it now!');
  }
},
  function(response) {
    console.log('publishStory response: ', response);
  });
  return false;
}
</script>

And here's what this results in:

enter image description here

So as you can see, it's quite different. Could anybody please tell me how to achieve publishing the story with 'X is playing a game on Y'?

1

There are 1 answers

0
Oz Solomon On

The reason for the difference is that you are publishing a stream post with your code, but the picture you have at the top is a result of an Open Graph action story.

You can read the documentation here: https://developers.facebook.com/docs/opengraph/using-actions/

Note that an action " is Playing " is not allowed by Facebook. Have a look at https://developers.facebook.com/docs/opengraph/submission-process/. It falls under this restriction:

User browses content in the app. A story is automatically published back to the user's timeline and to the news feed of friends that the person "browsed" content. Allowed? No

However, Facebook will automatically generate a similar story for you in some of the user's friend's timelines, so you don't actually need to do anything!