Predefined Text Directly Posted On Facebook Wall
i am using facebook android sdk provided for facebook i m using their examples-simple provided by them and its working very finely , now on login in fb show a form from fb to post
Solution 1:
Write below two functions into your Activity.
publicvoidpostToWall() {
String message="Good Morning to All";
Bundle parameters = new Bundle();
parameters.putString("message", message);
parameters.putString("description", "topic share");
try {
facebook.request("me");
String response = facebook.request("me/feed", parameters, "POST");
Log.d("Tests", "got response: " + response);
if (response == null || response.equals("") || response.equals("false")) {
showToast("Blank response.");
} else {
showToast("Message posted to your facebook wall!");
}
} catch (Exception e) {
showToast("Failed to post to wall!");
e.printStackTrace();
}
}
2)
publicbooleanrestoreCredentials(Facebook facebook) {
SharedPreferencessharedPreferences= getApplicationContext().getSharedPreferences(KEY, Context.MODE_PRIVATE);
facebook.setAccessToken(sharedPreferences.getString(TOKEN, null));
facebook.setAccessExpires(sharedPreferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
3)
publicvoidloginAndPostToWall() {
facebook.authorize(this, PERMISSIONS, Facebook.FORCE_DIALOG_AUTH, new LoginDialogListener());
}
Write below code into your wall post button click event
facebook = newFacebook(APP_ID);
restoreCredentials(facebook);
if (!facebook.isSessionValid()) {
loginAndPostToWall();
} else {
postToWall();
}
Post a Comment for "Predefined Text Directly Posted On Facebook Wall"