Android Boy
Android Boy

Reputation: 4345

Post the comment on any wall of Facebook in Android

I am using Facebook sdk, (https://github.com/facebook/facebook-android-sdk/) to show the NewsFeed. I can be show the all newsfeed wall in my application.

Now I need to send the comment on the any wall which is visible by me. And how I can be like the wall and the comment through my application. Can anybody plz help me in this?

Thanks in advance.

Upvotes: 2

Views: 5773

Answers (4)

Juicy Scripter
Juicy Scripter

Reputation: 25918

You should get familiar with Facebook Android SDK usage of Graph API, Post object (comments connection) and Comment Object Graph API documentation (likes section).

  • You can't comment on the wall itself but on one of the posts.
  • You can post on the wall via Graph API
  • You can comment on post via Graph API
  • You can create likes for both Posts and Comments via Graph API

Update:

Example below about creating comment and liking it (samples of how to create comment for post and like the post already shown in other answer to this question):

// I assume you already have post_id (which is constructed from USERID_MESSAGEID)
Facebook mFacebook = new Facebook(APP_ID);
Bundle params = new Bundle();
params.putString("message", "This is a comment text");
String comment_id = facebook.request(post_id + "/comments", params, "POST");

// Once you have comment_id it can be used for liking it.
facebook.request(comment_id + "/likes", new Bundle(), "POST");

Upvotes: 0

bindal
bindal

Reputation: 1932

You can parse all feeds using graph api by passing

mAsyncRunner.request("me/home", params, new graphApiRequestListener());

it returns you json data with all your post and comments and likes you can parse that data get all commnets

for further information search for hackbook for android example

Upvotes: 0

dstricks
dstricks

Reputation: 1485

To be clear:

  • you can only comment on posts (not the actual wall itself)
  • you can only like a comment or post (not the actual wall itself)

Using the Facebook SDK you can do the following for comments:

Facebook facebook = new Facebook(APP_ID);
String commentText = "I love blu-ray";
String postId = "7568536355_333422146668093"; //a lifehacker post about blu-ray

String graphPath = postId + "/comments";
Bundle params = new Bundle();
params.putString("message", commentText);
facebook.request(graphPath, params, "POST");

... and the following for likes:

Facebook facebook = new Facebook(APP_ID);
String postId = "7568536355_333422146668093"; //a lifehacker post about blu-ray

String graphPath = postId + "/likes";
facebook.request(graphPath, new Bundle(), "POST");

Upvotes: 7

sai
sai

Reputation: 2562

 'Use Facebook Api as library download api and use it as library'







    private static final String FACEBOOK_APPID = "Your Api key";

                Facebook facebook = new Facebook(FACEBOOK_APPID);

      facebook.authorize(this,new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" },
                             new DialogListener() {
                                @Override
                                public void onComplete(Bundle values) {
                                    postImageonWall();
                                    try {
                                        facebook.logout(TestActivity.this);

                                    } catch (MalformedURLException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                    }
                                    // finish();

                                }

                                @Override
                                public void onFacebookError(FacebookError error) {

                                }

                                @Override
                                public void onError(DialogError e) {

                                }

                                @Override
                                public void onCancel() {

                                }

use postImageOnWall method

            public void postImageonWall() {

                    byte[] data = null;

                    Bitmap bi = BitmapFactory.decodeFile(filepath);
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
                    data = baos.toByteArray();
                AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
                    mAsyncRunner.request(null, params, "POST", new RequestListener() {

                        @Override
                        public void onMalformedURLException(MalformedURLException e,
                                Object state) {
                            Log.d("MalformedURLException", e.getMessage());
                        }

                        @Override
                        public void onIOException(IOException e, Object state) {
                            Log.d("onIOException", e.getMessage());
                        }

                        @Override
                        public void onFileNotFoundException(FileNotFoundException e,
                                Object state) {
                            Log.d("FileNotFoundException", e.getMessage());
                        }

                        @Override
                        public void onFacebookError(FacebookError e, Object state) {
                            Log.d("onFacebookError", e.getMessage());
                        }

                        @Override
                        public void onComplete(String response, Object state) {
                            Log.d("onComplete", response);
                        }
                    }, null);

                }

Upvotes: -1

Related Questions