3
votes

I am posting on my wall in facebook sdk android but I am getting I'll post my code below

{Response: responseCode: 403, graphObject: null, error: {HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) The user hasn't authorized the application to perform this action}, isFromCache:false} private void postStatusUpdate(final String fbpost) { Log.d("postStatusUpdate",fbpost);

       Session.openActiveSession(this, true, new Session.StatusCallback() {
            // callback when session changes state
            @SuppressWarnings("deprecation")
            @Override
            public void call(final Session session, SessionState state, Exception exception) {
            if(session.isClosed()){
                 Log.i("postStatusUpdate session.isClosed", "message not posted session is closed");
             }
             if (session.isOpened()) {
               Log.i("session.isOpened", "session.isOpened");

             if (!session.isOpened()) { 
                Log.w("myConsultant11111111111","Session closed");
                Session.OpenRequest openRequest = null;
                openRequest = new Session.OpenRequest(TabActivity.this);

                if (openRequest != null) {
                    openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
                    openRequest.setPermissions(Arrays.asList("publish_stream","publish_actions"));
                    openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

                   session.openForPublish(openRequest);
                }

            }

             Log.i("session.getPermissions() tab", ""+session.getPermissions());


                //fbpostcheck = "if";

               // make request to the /me API
                Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                  // callback after Graph API response with user object
                  @Override
                  public void onCompleted(GraphUser user, Response response) {
                   //session.requestNewReadPermissions(newPermissionsRequest2);

                    if (user != null) {
                      try {

                        Session session = Session.getActiveSession();
                        //session.requestNewReadPermissions(newPermissionsRequest);
                        if (!session.isOpened() && !session.isClosed()) {
                           // session.openForRead(new Session.OpenRequest(this).setCallback(statusCallback));

                        } else {
                           // Session.openActiveSession(this, true, statusCallback);
                            Log.d("myLogs", "Test 1");
                            final String message = fbpost;
                            Request request = Request
                                    .newStatusUpdateRequest(Session.getActiveSession(), message, new Request.Callback() {
                                        @Override
                                        public void onCompleted(Response response) {
                                            //showPublishResult(message, response.getGraphObject(), response.getError());
                                             Log.i("onCompleted", response.toString());
                                             Log.i("getGraphObject", ""+response.getGraphObject());

                                             showPublishResult(message, response.getGraphObject(), response.getError());
                                        }

                                        private void showPublishResult(String message,GraphObject graphObject,FacebookRequestError error) {
                                            // TODO Auto-generated method stub
                                            String title = null;
                                            String alertMessage = null;
                                            if (error == null) {
                                                title = "Success";

                                                alertMessage = "All is good";
                                                //Toast.makeText(getApplicationContext(),"Posted successfully", Toast.LENGTH_SHORT).show();
                                                AppMsg.makeText(TabActivity.this, "Posted to facebook", AppMsg.STYLE_INFO).show();
                                            } else {
                                                title = "Error";
                                                alertMessage = error.getErrorMessage();
                                                Log.i("alertMessage", alertMessage.toString());
                                                AppMsg.makeText(TabActivity.this, "Error in Posting Message on facebook\n"/*+alertMessage*/, AppMsg.STYLE_INFO).show();
                                                //Toast.makeText(getApplicationContext(),alertMessage, Toast.LENGTH_LONG).show();

                                            }
                                        }
                                    });
                            request.executeAsync();
                        }

                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                         Log.i("Exception user data", e.toString());
                    }

                    }

                  }

                });




             }

            }

       });


    }
1
Are you sure you gathered "publish_actions" permission?Tobi
that is the issue i 'm facing , the permission dialogue for publish_stream is not opening when session is open, can you guide me where should i change in my code?Achin
There's an example on how to implement login you can find under developers.facebook.com/docs/android/scrumptious/authenticate if you don't know it already...Tobi

1 Answers

3
votes

just open the permission dialogue with the publish_action permission then update your access token and then post your message

facebook Post on your behalf is not working in android facebook sdk 3.0.2