How To Publish Actions On Timeline

By | November 11, 2011

This is my second tutorial of Facebook application development with Open Graph series, in previous tutorial I showed you how to setup your Facebook application with Open Graph. Now in this tutorial I will teach you to how to publish actions on user’s timeline.

Note: Due to changes announced by Facebook on 31st May this tutorial has been updated you can visit the updated tutorial from here.

How to Publish Actions on User’s Timeline
If you have already created actions and objects by following my previous tutorial then the next setup is to publish those actions on user’s timeline, but before proceeding you can check my demo app.

Step 1: Go to select the relevant app if you have multiple apps and click on Edit open Graph in Open Graph section.

Step 2: Click on Get Code in Object Types and copy the highlighted code from popup window and save it somewhere.

Step 3: Click on Get Code in Action Types and copy access token as shown in the second image and save it also.

Step 4: Now create a file test.html, paste the following code in it, replace the colored text according to your app’s settings and upload it to your hosting server

<html xmlns="" dir="ltr" lang="en-US"

Paste the code copied in step 2 here and don’t forget to replace Put Your Own URL Here with in og:url, set descriptions and image according to you page content.

<script type="text/javascript">
function read()
FB.api(‘/me/Your_Namespace:action‘ +
‘? the access token copied in step 3‘,’post’,
function(response) {
var msg = ‘Error occured';
if (!response || response.error) {
if (response.error) {
msg += "nnType: "+response.error.type+"nnMessage: "+response.error.message;
else {
alert(‘Post was successful! Action ID: ‘ +;


<div id="fb-root"></div>
<script src=""></script>
appId:’Your_appId‘, cookie:true,
status:true, xfbml:true, oauth:true
<input type="button" value="Post To Your Timeline " onclick="read()" />

Your_Namespce: In my demo app it was onlytipsandtricks change it according to your app.

Action: In demo app it was read but when you click on get code as you did in step 3 you will see underscore after read as read_

You have to include these underscores in both actions and objects otherwise you will get the following error:

The action you’re trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: article_.

Object: We used object article in demo app so you have to replace it according to object settings of your app.

Your_appId: You application id.

Finally you can test your page by visiting and clicking on Post To Your Timeline button, if all things go well you will see Post was successful! message along with app id on your page.

52 thoughts on “How To Publish Actions On Timeline

  1. Andrei

    When I click “Publish to Timeline” button I get an error “session is expaired”.

  2. Patel pranay

    when I click on “publish to timeline”, nothing happens! :( Help soon if possible

  3. peeyush

    The action you’re trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: article_.

    I am getting the above error as per your doc. i have made chages but not working plz tell wat i do for it .

    1. Hasnain Post author

      Have you added underscore “_” after “article_” in this line FB.api('/me/Your_Namespace:read_' +
      '? the access token copied in step 3','post',

        1. Hasnain Post author

          I have checked your page on Debugger its ok, if you added the same objects and actions types in your app and still you are getting this error then may be its a Facebook bug many people are complaining this, here is same question from stackoverflow although its related to submitting the object.

  4. Akansh

    Hello!i loved ur article and want to know is it possible that when any person visit my blog and read any article ,when he reads it get posted on facebook that That person has read an today big sites have this feature.please help/

    1. Hasnain Post author

      Yes its possible but first thing you need is the user visiting your site for reading articles must authenticate your app before read action can be posted to his timeline, you can use “add to timeline plugin” for this purpose. The other thing is your pages must have open graph meta tags matching with your app’s actions and objects, if you have self hosted wordpress blog there are few plugins with can add meta tags to your pages.

      1. Akansh

        But i am using blogger and it`s really difficult to start that service.Can You write a tutorial for enabling that sevice for a blog.My blog is

        1. Jano

          Hello Hasnain:

          I want exactly what Akansh described.

          I am already using a plugin for OGP meta tags that is doing its job very well. But I can not find an “Add to timeline plugin”. Would you point me in the right direction? Thanks a lot.

  5. Janusz Jasinski

    I keep getting this:

    Message: The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: article.

    I’ve followed this article down to the last full stop but no luck.

    Any ideas?


    1. Janusz Jasinski

      Ok – I clearly didn’t see everything! Brilliant – thanks.

      Someone did mention a good example of something I’m look to do

      1) If app not authenticated
      1.1) Show “Add to Timeline” or “Authenticate this App” button
      2) If app is authenticated
      2.1) Run the function to add the “read an article” to the timeline
      2.2) If they come back to the page, check if the actio has already been submitted
      2.3) If submitted already i.e. already seen article, don’t add again

      1. Hasnain Post author

        1. You can add the “Add to timeline” plugin, by using this plugin if the user is not authenticated he will be shown “Add to timeline button” and if the user already added the app then “added to timeline” will be shown.
        2. If user is authenticated with publish_actions permission then you can publish “read” actions by allowing user to click on the custom button as we did in the example or you can call javascript function by using this bit of codeonload="read() so that when the user clicks on link to article the action will be posted automatically when the page will be loaded.

  6. AkRy

    HI !
    I’ve followed your tutorial step by step and it’s still not working…
    I’ve got my app on my application page and i see
    Add to timeline when i click on it nothing happenned to my timeline :(
    I have also a message error which is
    Message(#3502) Object at URl “my URL” has og:type of’website’
    The property ‘article’ requires an object of og:type ‘testserd:article’
    **testserd is my app namespace

    Do you know how to fix this?

          1. Avinash Agrawal

            Yes… Now it is showing error….

            The action you’re trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: article.

        1. Avinash Agrawal

          I am getting this in Action type

          FB.api(‘me/news.reads’ …….

          Instead of


          Semicolon is missing ???

  7. Avinash Agrawal

    Erro code(#100) Can only call this method on valid test users for your app”

    but after sometime
    error: session has expired at unix time……

    What is this?? plz help me out

    1. Hasnain Post author

      “Session expired” means the access token has expired the token usually expires within two hours, now you have to copy the the token again as mentioned in step 3.

  8. JC

    i tried everything but nope, nothing happens when i click “post to my timeline”. why do you think i am even not getting an error message? thanks in advance

    1. Hasnain Post author

      First make sure that all the code is in plain text, if you have copied the code from here then chances are that you have copied the formatted text and you have to convert it into plain text, if the code you have copied is already in plain text then check if you have correctly loaded the SDK and additionally you can check the source code of my app.

    1. Hasnain Post author

      I am out of thoughts because the link you have posted is not working anyways i guess it is, i have checked your pages source code its showing strange characters.

  9. cateno

    I followed the example above but i keep receiving tha same erron when i click in “publish” button:

    Message: (#15) This method must be called with an app access token.

    any ideia?

  10. Julie Carter

    Unknown Object Type: Object at URL ‘′ is invalid because the configured ‘og:type’ of ‘430460170298259:group’ is invalid.

    No Matter what I do, I keep getting this error message when I debug sample data. Any ideas?


  11. Kpoulianos

    I have the same problem others mentioned. Message (#3502) Object at url…has og:type of ‘website’. The property ‘article’ requires an object of og:type ‘article’.

    Here is the link to the article

    Thanks for writing this tutorial, it’s been great help.

    1. Hasnain Post author

      You should check your URL in debugger and if it shows no error and og tags are same as of your app then may be its a bug.

      1. Kpoulianos

        The debugger indeed showed no errors, but in fact there was an error in the API call wich I fixed, everything is working now. The only problem I still have is that the access token copied and pasted in “step 4″ expires after 2 hours and I need to request a fresh read code, and paste the new token. Any way to do this automatically, or to make tokens not expire?

  12. Sana

    Boss I’m getting a Window saying,

    Error occurred

    Type: OAuthException

    Message: An active token must be used to query information about the current user.

    ==>>> Breaking head since noon, Would be helpful if u reply within tomorrow noon, Pleaseee

  13. Deb Bhattrai

    hi hassin,
    i’ve read the article carefully. there is no underscore in the code which i got from step 3. so i did not put in the code. i still get error like:

    Error occured

    Type: Exception

    Message: The action you’re trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: cusine.

  14. Thy

    There seems to be some error with documentation and the fb.api. After playing around with the code I got it to work. Please view my same code here:

    note that my fb.api call has been modified to:
    { article: ‘’ },

    Publish is the Action Type
    article is the object.

  15. Pingback: Facebook plug-in for Wordpress « No Pen Only TeXt

Leave a Reply

Your email address will not be published. Required fields are marked *