Posting comments to Facebook page using Java

I am trying to post comments on an app page on Facebook. My application is written in java using spring MVC. The functionality I would like to implement is whenever I post text to my page from my back office, the same message that will be posted to my Facebook page. So far I have done this for Twitter and it works really well. On Facebook, I ran into a problem. From what I have found, the only API that is almost updated is RestFB. I tried the following as the example shows:

FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);
FacebookType publishMessageResponse =
facebookClient.publish("me/feed", FacebookType.class,
Parameter.with("message", "RestFB test"));


I created my app at and I got an access token there. But this led to the exception that I have no rights. I searched the web and I came across a post here: Facebook: Send an invitation to the app

And I tried this example too. The result was the same that I don't have the correct permissions. I have double checked the permissions I issue and all the relevant ones are allowed.

Can someone please help me. Is this api up to date? I check and the last published date was October 2011 and I know Facebook made some changes after the new year. Also, are there any other better api? Finally, if anyone knows how to do this, they can post an example here.

@Alexandre @Tartoth

I am posting with the admin of the page that is my self at the moment and yet it gives me an error. Here is the code I am using to post a comment. I'm new to this, so maybe I was doing something wrong

String tokenUrl = "" + appId + "&client_secret=" + appSecret
                + "&grant_type=client_credentials";
        HttpClient client = new HttpClient();
        HttpMethod method = new GetMethod(tokenUrl);

        String rawAccessToken = new String(method.getResponseBody());

        String accessToken = rawAccessToken.split("=")[1];

        FacebookClient facebookClient = new DefaultFacebookClient(accessToken);
        String to = appId +"/feed";

        facebookClient.publish(to, FacebookType.class,
                Parameter.with(msg, "RestFB test"));


Update: I've resolved an earlier issue. And now my application is receiving the Token application and I can use it to post messages, but the problem is that these messages cannot be viewed on the application page. I know the post has been posted because I can access it using . Now my new question is:

Is this the correct way to display messages on the app page? The reason for this question is that on the application page, it itself, opening it directly from Facebook, only has an update status. But when I was looking at the RestFb api, there is no explanation on how you can update the application status.

If it is not, can someone explain to me how I can update the application status. The point of all I want to achieve is when I change something in my web app (in terms of posting some news), I want my status on my facebook app page to have the same news.


source to share

1 answer

You need to publish a page access token, which is the user (page administrator) that grants the "manage_pages" permission to the application.




All Articles