简体   繁体   中英

Post on facebook wall from server instead of client app

I have been working on an iphone app (with client-server communication) that connects to facebook via fConnect. The facebook authentication and other communication is being handled at iphone app and they all are working fine.

Now, due to some optimization issues we want to handle the fb wall post functionality of app from server side instead of client side. To achieve the task what we are doing is send all the data(includes fb access token as well) to server side and send a http post request to facebook via graph api. In the response it send us an error:

{"error":{"message":"Invalid token: \\"610446057\\". An ID has already been specified.","type":"OAuthException","code":2500}}

The sample code of http request is pasted below:

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

The server is written is Grails 2.0.1.

I have followed the fb post sample provided here: http://developers.facebook.com/docs/reference/api/

Can you please guide what I am doing wrong?

Thanks.

Zunair Minhas

All you have to do is remove the line:

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

You are passing that via the graph url https://graph.facebook.com/610446057


To post to a wall just do

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

Where the access token is the token the user gave you to write on the wall. When you do that it will resolve who you are sending the message to and post all the wall as the app that was authorized.

You are specifing an ID which you already have in the URL

try to remove

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM