问题
I'm trying to post comments on an app page in Facebook. My application is written in java using spring MVC. The functionality i like to implement is whenever i post some text on my page from my back-office the same message to be posted on my Facebook page. So far i've done this for Twitter and it works very well. On Facebook i ran in to a problem. From what i have found the only API that is almost up to date is RestFB. I tried the following as thier 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 on https://developers.facebook.com and i acquired the access token from there. But this resulted in an exception that i don't have the right permissions. I was searching the web an i ran into a post here: Facebook: send an app invitation
And i tried this example also. The result was the same that i don't have the correct permissions. I double checked the permissions i give out and all of the relevant once 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. Furthermore is there any other better api? And finally if someone knows how to do this can he post an example here.
@Alexandre @Tartoth
I am posting with the admin of the page that is my self at the moment and still it gives me an error. Here is the code that i am using to post a comment. I am new to this so maybe i'm doing somthing wrong
String tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + appId + "&client_secret=" + appSecret
+ "&grant_type=client_credentials";
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod(tokenUrl);
client.executeMethod(method);
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 solved the earlier problem. And now my app is getting it's app Token and i can use it to publish messages but the problem is those messages can not be viewed on the app page it self. I know the message is posted because i can access it using https://graph.facebook.com/publishedMessageId. Now my new question is:
Is this the correct way to display posts on the app page? The reason for this question is that on the app page it self when opening it directly from Facebook you have only update status. But when i was looking at the RestFb api there is no explanation on how u can updated the app status.
If this is not the way, can someone please explain to me how i can update the status as an app. Meaning all i want too accomplish is when i change something on my web application (in terms of publishing some news) i want my status on my facebook app page to have the same news.
回答1:
You need to post with a Page Access Token which is a user (admin of the page) who grant the "manage_pages" permission to the App.
Documentation: https://developers.facebook.com/docs/authentication/pages/
来源:https://stackoverflow.com/questions/9874914/posting-app-generated-comments-on-facebook-page-using-java