I am using Facebook API in my application to post messages to wall. Every thing work fine, but when I post message more than one time in a sort time interval, wall post doesn't appear on wall. I am sure there no any exception occurres while posting.
I use 'offline-access' permission with my application.
Code :
public static class UpdateWalls extends AsyncTask<String, Integer, Boolean> {
private Context context;
private String post;
public UpdateWalls(Context context, String post) {
this.context = context;
this.post = post;
}
@Override
protected Boolean doInBackground(String... strings) {
FacebookConnector facebookConnector = new FacebookConnector(Constants.FACEBOOK_APPID, context, Constants.FACEBOOK_PERMISSION);
try {
facebookConnector.postMessageOnWall(this.post);
} catch (Exception e) {
return false;
}
return true;
}
}
and FacebookConnector.postMessageOnWall() is
public void postMessageOnWall(String msg) {
if (facebook.isSessionValid()) {
Bundle parameters = new Bundle();
parameters.putString("message", msg);
try {
String response = facebook.request("me/feed", parameters,"POST");
Log.i("Facebook wall post", "While posting to wall response = " + response);
//System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
}
} else {
//login();
}
}
Is this a known issue or something else? Please help me.
Thank you.
The Facebook API, in most cases, won't throw exceptions even if the request fails. Error status is returned by the response to the call. In this line here:
Log.i("Facebook wall post", "While posting to wall response = " + response);
You're writing a log with the response. What is that response? What is it when the wall post succeeds compared to when it fails?
It seems facebook reject requests when they come in too fast, see this question for a short but possibly out-of-date discussion on API limits. If you're getting a response that suggests you're making too many requests, you could add a delay and try again.