Posting A Text Status Using Facebook Api In Android - The Simplest Method
I have been searching a lot to find a way to do this. But nothing seems to be working for me. Can someone please help in doing this? This is my image button for facebook status pos
Solution 1:
Assuming that you want to post on your own wall (since the question is not clear), this should work for you.
publicclassMainActivityextendsActivity {
privatestatic final StringAPP_ID = "xxxxxxxxxxxxx";
privateFacebook mFacebook;
privateAsyncFacebookRunner mAsyncRunner;
privateEditText yourEditText;
privateString toShare;
@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mFacebook = newFacebook();
mAsyncRunner = newAsyncFacebookRunner(mFacebook);
SessionEvents.addAuthListener(newSampleAuthListener());
SessionEvents.addLogoutListener(newSampleLogoutListener());
yourEditText = (EditText) findViewById(R.id.<youreditTextId>);
toShare = yourEditText.getText().toString();
}
publicvoidshareOnFacebook(View v) {
Bundle params = newBundle();
params.putString("message", toShare);
mAsyncRunner.request("me/feed", params, "POST", newRequestListener() {
publicvoidonMalformedURLException(MalformedURLException e) {}
publicvoidonIOException(IOException e) {}
publicvoidonFileNotFoundException(FileNotFoundException e) {}
publicvoidonFacebookError(FacebookError e) {}
publicvoidonComplete(String response) {
}
});
Toast.makeText(MainActivity.this, "Posting to your Wall", Toast.LENGTH_SHORT).show();
}
}
For details on posting pictures to wall, Facebook has a good documentation.
Solution 2:
The simplest way to post message on user`s wall who is successfully login using your android application is(my working code)_
publicclassAndroidFacebookWallPostextendsActivity {
// Your Facebook APP ID:privatestaticStringAPP_ID = "your App ID here"; //// Instance of Facebook Class:privateFacebook facebook;
privateAsyncFacebookRunner mAsyncRunner;
// Your ImageButton that Post Message to Facebook Wall:ImageButton btnPostToWall;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnPostToWall = (ImageButton) findViewById(R.id.imageButton1);// Your image button...
facebook = newFacebook(APP_ID);
mAsyncRunner = newAsyncFacebookRunner(facebook);
// set listener for Post Message button
btnPostToWall.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
postToWall();
}
});
}
/**
* Method that Post a Text Status using Facebook API on user`s wall.
*/publicvoidpostToWall() {
// post on user's wall.
facebook.dialog(this, "feed", newDialogListener() {
@OverridepublicvoidonFacebookError(FacebookError error) {
Toast.makeText(AndroidFacebookWallPost.this, "Post fail "+error, Toast.LENGTH_LONG).show();
}
@OverridepublicvoidonError(DialogError error) {
Toast.makeText(AndroidFacebookWallPost.this, "Post fail due to "+error, Toast.LENGTH_LONG).show();
}
@OverridepublicvoidonComplete(Bundle values) {
Toast.makeText(AndroidFacebookWallPost.this, "Post success.", Toast.LENGTH_LONG).show();
}
@OverridepublicvoidonCancel() {
Toast.makeText(AndroidFacebookWallPost.this, "Cancle by user!", Toast.LENGTH_LONG).show();
}
});
}
}
for more please gone through Getting Started with the Facebook SDK for Android.
Solution 3:
Here is details of variable that you can out in bundle
Bundle params = new Bundle();
params.putString("message", "This string will appear as the status message");
params.putString("link", "This is the URL to go to");
params.putString("name", "This will appear beside the picture");
params.putString("caption", "This will appear under the title");
params.putString("description", "This will appear under the caption");
params.putString("picture", "This is the image to appear in the post");
And use AsyncFacebookRunner for post data to facebook :
mAsyncRunner.request("me/feed", params, "POST", newRequestListener() {
publicvoidonMalformedURLException(MalformedURLException e) {}
publicvoidonIOException(IOException e) {}
publicvoidonFileNotFoundException(FileNotFoundException e) {}
publicvoidonFacebookError(FacebookError e) {}
publicvoidonComplete(String response) {
}
});
Post a Comment for "Posting A Text Status Using Facebook Api In Android - The Simplest Method"