Publish on Facebook WALL using Java

Before writing this article it took me around 1 week to figure out how i can use Facebook Graph API to publish message to WALL. Well there is no proper documentation available but with this article we will learn on how we can publish feed to Facebook WALL using Graph API. We would be using Java as our programming language but it can be done using CURL in PHP and C/C++ as well.

Facebook Publish WALL API:
As per Facebook Graph API, the URL to publish feed to user WALL is$PROFILE_ID$/feed. We would be using Apache HttpClient for performing HTTP POST operation. Apache HttpClient can be downloaded from Apache HttpClient.

HTTP Form Post Request Using Ajax and Request

Pre-Requisite for Publishing Message tn Facebook:
For publishing message on Facebook WALL we would require additional user information like Access Token and User Id. Access Token is the unique key assigned to every account registered to an facebook application. Apart from this there are additional POST data that we have to send to Publish URL like Message, Application Canvas URL, Application Name, Caption and Action(Indicating external Http Link). Now let gets started with the code for publishing message to Facebook WALL.


– The response from facebook would be an JSON string and if there is any error than you will receive “id” in
JSON string.
– You can download JSON library from

Tagged . Bookmark the permalink.

3 Responses to Publish on Facebook WALL using Java

  1. Dunnow says:

    This code does not work at all… and it lacks of some “;” and “{” or “}” … also will be nice a little explaination of “userId = “[USER FACEBOOK ACCOUNT ID]”” what does this mean? the ID numer? the ID name of the account? what?

    did you even try this code before posting it?

  2. Hi Dunnow,
    I have tried this code and it was working properly when i had posted it. When i was working on Facebook module i have also faced lot of problems related to API consistency.

    USER FACEBOOK ACCOUNT ID – Refers to Profile Id that is assigned by Facebook for every account.

    As per the Facebook Message API JSON response is required only in actions param.

    Overall my experience was bad with Posting Message on Facebook WALL but finally was able to post an message and if there is some changes from Facebook end than this would require changes.

    Thanks & Regards,
    Hitesh Agarwal

  3. Mitesh says:

    Hi Hitesh,

    As i am using your Java Graph Api and Get the response :

    uploadResponse{“error”:{“message”:”(#200) The user hasn’t authorized the application to perform this action”,”type”:”OAuthException”,”code”:200}}
    – Message could not be published to WALL
    org.json.JSONException: JSONObject[“id”] not found.
    at org.json.JSONObject.get(
    at org.json.JSONObject.getString(
    at com.crowdperks.admin.mail.Facebook.main(

    Can you please check on it and let me know if i have any problem.

Leave a Reply