使用Java在Facebook页面上发布应用程序生成的评论 [英] Posting app-generated comments on Facebook page using Java

查看:136
本文介绍了使用Java在Facebook页面上发布应用程序生成的评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Facebook的应用页面上发表评论.我的应用程序是使用Spring MVC用Java编写的.我想实现的功能是,每当我在后台将一些文本发布到我的页面上时,就会在Facebook页面上发布相同的消息.到目前为止,我已经在Twitter上做到了这一点,并且效果很好.在Facebook上,我遇到了一个问题.根据我的发现,RestFB是几乎最新的唯一API.我尝试了以下示例所示的方法:

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"));

我在 https://developers.facebook.com 上创建了我的应用,并从以下网站获取了访问令牌那里.但这导致了一个例外,即我没有正确的权限.我正在网上搜索,然后在这里遇到了一个帖子: Facebook:发送应用邀请

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.

有人可以帮助我吗?这个api是最新的吗?我查看了一下,最后发布的日期是2011年10月,我知道Facebook在新的一年之后做了一些更改.此外,还有其他更好的API吗?最后,如果有人知道该怎么做,他可以在此处发布示例.

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

@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"));

更新: 我解决了之前的问题.现在我的应用程序正在获取它的应用程序令牌,我可以使用它来发布消息,但是问题是那些消息无法在其自身的应用程序页面上查看.我知道邮件已发布,因为我可以使用 https://graph.facebook.com/publishedMessageId.现在我的新问题是:

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:

这是在应用页面上显示帖子的正确方法吗?出现此问题的原因是,在应用程序页面上,当直接从Facebook直接打开它时,它只有更新状态.但是当我查看RestFb api时,没有关于如何更新应用程序状态的解释.

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.

如果不是这样,有人可以向我解释我如何更新应用程序状态.意思是我想做的就是在更改Web应用程序上的某些内容时(就发布一些新闻而言),我希望我的facebook应用程序页面上的状态具有相同的新闻.

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.

推荐答案

您需要发布一个页面访问令牌,该令牌是向应用授予"manage_pages"权限的用户(页面管理员).

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.

文档: https://developers.facebook.com/docs/authentication/pages/

这篇关于使用Java在Facebook页面上发布应用程序生成的评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆