Skip to content Skip to sidebar Skip to footer

Facebook Wall Post Error From Android App?

I have successfully integrated FB with my app.I want to auto post some text,links,images to my facebook wall after giving app permission from facebook account.I have tried using be

Solution 1:

The error message means that you did not authorize the user with publish_actions. Test the Access Token in the Debugger to find out which permissions are authorized: https://developers.facebook.com/tools/debug/

Btw, you will not get read_stream approved in the review process: https://developers.facebook.com/docs/facebook-login/permissions/v2.3#reference-read_stream

...meaning, it will only work for Users with a role in the App (Admin, Developer, Tester).

Solution 2:

finally after lots of research i have modified my class correctly.Here i am posting my modified code that may help others.

publicclassMainFragmentextendsFragment {
privatestatic final StringTAG = "MainFragment";
privateUiLifecycleHelper uiHelper; 

privateSession.StatusCallback callback=newSession.StatusCallback(){
    @Overridepublicvoidcall(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }

};  

privatevoidonSessionStateChange(Session session, SessionState state, Exception exception) {
    if (state.isOpened()) {
        Log.i(TAG, "Logged in...");
        publishStory(session);
    } elseif (state.isClosed()) {
        Log.i(TAG, "Logged out...");
    }
}


publicvoidpublishStory(Session currentSession) {
     Bundle params = newBundle();
     params.putString("message", "Hey I am using this app");
        params.putString("name", "Dexter");
        params.putString("caption", "londatiga.net");
        params.putString("link", "http://www.londatiga.net");
        params.putString("description", "Dexter, seven years old dachshund who loves to catch cats, eat carrot and krupuk");
        params.putString("picture", "http://twitpic.com/show/thumb/6hqd44");                                                

     WebDialog feedDialog = (newWebDialog.FeedDialogBuilder(getActivity(),currentSession, params))
       .setOnCompleteListener(newOnCompleteListener() {

       @OverridepublicvoidonComplete(Bundle values,FacebookException error) {
        if (error == null) {
         // When the story is posted, echo the success// and the post Id.
         final String postId = values.getString("post_id");
         if (postId != null) {
             Intent i=newIntent(getActivity(),MainActivity.class);//FacebookActivity.class);startActivity(i);
             getActivity().finish();                               // do some stuff
         } else {
         // User clicked the Cancel buttonToast.makeText(getActivity(),
           "Publish cancelled", Toast.LENGTH_SHORT).show();
         }
        } elseif (error instanceofFacebookOperationCanceledException) {
         // User clicked the "x" buttonToast.makeText(getActivity(),
          "Publish cancelled", Toast.LENGTH_SHORT).show();
        } else {
         // Generic, ex: network errorToast.makeText(getActivity(),
          "Error posting story", Toast.LENGTH_SHORT).show();
        }
       }

      }).setFrom("").build();
     feedDialog.show();

    }



@OverridepublicViewonCreateView(LayoutInflater inflater, 
        ViewGroup container, 
        Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.activity_facebook, container, false);
    LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);

    if(Session.getActiveSession().isOpened()){
        Toast.makeText(getActivity(), "logged in to FB", 1).show();
    }else{
        authButton.setFragment(this);
        authButton.setReadPermissions(Arrays.asList("public_profile"));
    }
    return view;
}

@OverridepublicvoidonCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    uiHelper = newUiLifecycleHelper(getActivity(), callback);
    uiHelper.onCreate(savedInstanceState);
}

@OverridepublicvoidonResume() {
    super.onResume();
    Session session = Session.getActiveSession();
    if (session != null &&
           (session.isOpened() || session.isClosed()) ) {
        onSessionStateChange(session, session.getState(), null);
    }

    uiHelper.onResume();
}

@OverridepublicvoidonActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

@OverridepublicvoidonPause() {
    super.onPause();
    uiHelper.onPause();
}

@OverridepublicvoidonDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@OverridepublicvoidonSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

}

Post a Comment for "Facebook Wall Post Error From Android App?"