I am Posting to groups on facebook but i have encounterd with 2 exceptions:
- could not construct body exception
- EOFException
I have tried many solutions but with no success.
including this:
System.setProperty("http.keepAlive", "false");
thanx :)
Oh and this run runs on a Service.
Session session = Session.getActiveSession();
if(session==null) session = Session.openActiveSessionFromCache(getApplication());
if (session != null){
Log.d("Post Service", "session not null");
// Check for publish permissions
List<String> permissions = session.getPermissions();
if (!isSubsetOf(PERMISSIONS, permissions)) {
pendingPublishReauthorization = true;
Log.d("Post Service", "No Permissions to Post!");
return;
}
Bundle postParams = new Bundle();
postParams.putString("name", "AutoPost");
postParams.putString("message", this.post);
if(!this.piclink.equals(""))postParams.putString("picture",
this.piclink);
for(int i=0; i<this.groupsIds.length;i++){
Log.d("Post Service", "posting to: "+this.groupsIds[i]);
Request request = new Request(session, this.groupsIds[i]+"/feed", postParams,
HttpMethod.POST);
if(this.appStatus.isOnline(this.getApplicationContext())){
Response resp = request.executeAndWait();
if(resp.getError()!=null){
Log.d("Post Service", "POST ERROR: "+resp.getError().toString());
Log.d("Post Service", "POST EXECEPTION: "+resp.getError().getException().toString());
this.notifMyUser("Post failed!post error",resp.getError().toString());
this.notifMyUser("Post failed!post exeception",resp.getError().getException().toString());
this.write("ErrorLog", this.groupsIds[i]+ ": "+resp.getError().toString());
this.write("ErrorLog", this.groupsIds[i]+ ": "+resp.getError().getException().toString());
}
else{
JSONObject graphResponse = resp
.getGraphObject()
.getInnerJSONObject();
String postName = null;
try {
postName = graphResponse.getString("id");
Log.d("Post Service", "post successful to: "+postName.toString());
this.write("ErrorLog", "post successfuly to: "+postName.toString());
this.notifMyUser("Post-Success!","post successful to: "+postName.toString());
} catch (JSONException e) {
Log.i("Post Service: ",
"trying to post, JSON error "+ e.getMessage());
}
}
}
else {
this.notifMyUser("Post-NoConnection", "faild to post to "+ this.groupsIds[i]);
this.write("ErrorLog", "faild to post to "+ this.groupsIds[i]);
}
}
}
}