How to integrate "Like" and "Comment" feature using Android Facebook SDK?
Asked Answered
C

1

10

I want to implement "Like" and "Comment" feature in my app. I used this code:

public static void like(String postID) {
String grapPath = String.format("%s/likes", postID);
Request request = new Request(Session.getActiveSession(), grapPath,
    null, HttpMethod.POST, new Callback() {
   @Override
   public void onCompleted(Response response) {
    Log.i(TAG, response.toString()+" Success!");
   }
});
Request.executeBatchAsync(request);
}

public static void postComment(String comment, String postID) {
String grapPath = String.format("%s/comments", postID);
Bundle bundle = new Bundle();
bundle.putString("message", comment);
Request request = new Request(Session.getActiveSession(), grapPath,
        bundle, HttpMethod.POST, new Callback() {
    @Override
    public void onCompleted(Response response) {
        Log.i(TAG, "Success!");
    }
});
    Request.executeBatchAsync(request);
 }

Hhow and where can I call these methods to make them work?

Cerebritis answered 15/8, 2013 at 3:32 Comment(4)
thank for your attendence, Pradeep! I made it worked :)Cerebritis
Great, would it possible for you to share some resource which helped you?Schutzstaffel
@Pradeep: Yes, this code worked, my problem was that i dont know how to useCerebritis
@SteveLuck Can you please share code i have same issue ThanksBaluchi
J
3

Please make sure the prerequisites are set up correctly. Specifically check out the middle of step 4 to make sure you generated your key hash correctly using your debug keystore.

Otherwise code below should help out

private boolean hasPublishPermission() {
        Session session = Session.getActiveSession();
        return session != null && session.getPermissions().contains("publish_actions");
    }
private void postStatusUpdate() {
       if (hasPublishPermission()) {
            final String message = "Posting to facebook";
            Request request = Request
                    .newStatusUpdateRequest(Session.getActiveSession(), message, place, tags, new Request.Callback() {
                        @Override
                        public void onCompleted(Response response) {
                            showPublishResult(message, response.getGraphObject(), response.getError());
                        }
                    });
            request.executeAsync();
        } else {
            pendingAction = PendingAction.POST_STATUS_UPDATE;
        }
    }
Jodijodie answered 22/1, 2014 at 0:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.