-1

In my android app I have multiple activities . I m lo-gin with Facebook and also i m able to post messages to Facebook wall and logout from facebook successfully.But when i login with another account I am able to logged in successfully but unable to post messages on facebook wall how can i post messages on facebook with multiple accounts(when i share message it goes previous user wall not in present user). Please provide any code or suggestions.this is my code.

      public boolean saveCredentials(Facebook facebook) {
 Editor editor = getApplicationContext().getSharedPreferences(KEY,
 Context.MODE_PRIVATE).edit();
 editor.putString(TOKEN, facebook.getAccessToken());
 editor.putLong(EXPIRES, facebook.getAccessExpires());
 return editor.commit();
 }

 public boolean restoreCredentials(Facebook facebook) {
 SharedPreferences sharedPreferences = getApplicationContext()
.getSharedPreferences(KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}


 public void share(View button) {
 msg = tv.getText().toString();
 System.out.println("THIS is message to firstposttttttttttttt" + msg);
 messageToPost = msg;
 System.out.println("THIS is message to posttttttttttttt"
 + messageToPost);
 if (!facebook.isSessionValid()) {
 loginAndPostToWall();

 } else {
 postToWall(messageToPost);
 }
 }
 public void loginAndPostToWall() {
 facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
 new LoginDialogListener());
 }

 public void postToWall(String message) {
 byte[] data = null;

   /* Bitmap bi = BitmapFactory.decodeFile(LoginActivity.hospitalImage);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
    data = baos.toByteArray();*/

 Bundle parameters = new Bundle();
//parameters.putString("picture","http://www.indiatalkies.com/images/hospitals18400l.jpg" );
 parameters.putString("message", message);
 parameters.putString("link", "http://redkansoftware.com/");
  parameters.putString("description", "topic share");

 try {
 facebook.request("me");
 String response = facebook.request("me/feed", parameters, "POST");
 // facebook.dialog(this, "feed", parameters,new
 // LoginDialogListener());
 Log.d("Tests", "got response: " + response);
 System.out
 .println("this is respose from facebookkkkkkkkkkkkkkkkkkkk"
   + response);
 if (response == null || response.equals("")
 || response.equals("false")) {
 showToast("Blank response.");

 } else {

 showToast("Message posted to your facebook wall!");

 }

 finish();
 } catch (Exception e) {
 showToast("Failed to post to wall!");
 e.printStackTrace();
 finish();
 }
 }
   for logout am using ths code
   Util.clearCookies(youractivity.this);
    SessionStore.clear(youractivity.this);




          thanks in advance.......
vimalatha
  • 63
  • 1
  • 10

1 Answers1

0

I kinda faced the same problem. and update below code to solve it.

   public void loginAndPostToWall() {
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
        new LoginDialogListener());

}

News
  • 11
  • 1