在我的 android 应用程序中,我有多个活动。我在 Facebook 上登录,也可以在 Facebook 墙上发布消息并成功从 facebook 注销。但是当我使用另一个帐户登录时,我能够成功登录但无法在 facebook 墙上发布消息我该如何发布消息在具有多个帐户的 facebook 上(当我分享消息时,它会转到以前的用户墙而不是当前用户)。请提供任何代码或建议。这是我的代码。
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.......