在我的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.......
答案 0 :(得分:0)
我有点面临同样的问题。并更新以下代码来解决它。
public void loginAndPostToWall() {
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH,
new LoginDialogListener());
}