从服务器而不是客户端应用程序在Facebook墙上发布

时间:2012-03-07 12:23:40

标签: iphone facebook grails httpwebrequest facebook-wall

我一直致力于通过fConnect连接到facebook的iphone应用程序(带有客户端 - 服务器通信)。 Facebook验证和其他通信正在iphone应用程序处理,它们都正常工作。

现在,由于一些优化问题,我们希望从服务器端而不是客户端处理应用程序的fb wall post功能。为了完成任务,我们正在做的是将所有数据(包括fb访问令牌)发送到服务器端,并通过图形api向facebook发送http post请求。在回复中,它向我们发送了一个错误:

  

{“error”:{“message”:“无效令牌:\”610446057 \“。一个ID已经   已指定。“,”类型“:”OAuthException“,”code“:2500}}

http请求的示例代码粘贴在下面:

HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", "Test Client");

PostMethod method = new PostMethod("https://graph.facebook.com/610446057?access_token=MY_VALID_TOKEN_HERE");
method.addParameter("id", "610446057");
method.addParameter("name", "Zunair Minhas");
method.addParameter("picture", "http://profile.ak.fbcdn.net/hprofile-ak-ash2/276791_19292868552_1958181823_s.jpg");
method.addParameter("link", "http://www.google.com.pk");
method.addParameter("company_overview", "FB Wall post without fb integration. It is a simple Http Post request.");
client.executeMethod(method);

def reader = method.getResponseBodyAsString();
String data = reader.readLines().join()
method.releaseConnection();

服务器编写的是Grails 2.0.1。

我已按照此处提供的fb post示例:http://developers.facebook.com/docs/reference/api/

你能指导我做错了吗?

感谢。

Zunair Minhas

2 个答案:

答案 0 :(得分:1)

您所要做的就是删除该行:

method.addParameter("id", "610446057");

您是通过图表网址https://graph.facebook.com/610446057

传递的

要张贴到墙上,请执行

https://graph.facebook.com/me/feed?access_token=<xxx>

访问令牌是用户在墙上写的令牌。当您这样做时,它将解析您将消息发送给谁并将所有墙发布为已授权的应用程序。

答案 1 :(得分:0)

您正在指定URL中已有的ID

尝试删除

method.addParameter("id", "610446057");