2

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]);
        }

       }

     }
   }
Yakir Yehuda
  • 650
  • 7
  • 23

1 Answers1

0

Let me try once i use this repo :) just check my previous project , in this case you may missing to add dependencies properly if you added dependencies then rebuild and clean your project and then check imported R files which exactly .

Osman Goni Nahid
  • 1,193
  • 2
  • 15
  • 24