0

According to https://developers.facebook.com/docs/reference/api/, we can like a comment. I am able to post a comment but i am not getting a point of how to like a comment. I have wrote a code below to confirm, is the syntax is correct or not plus it is giving an excecption also.

static private String MY_ACCESS_TOKEN = "AAACEdEose0cBAARk6nVpaOZCTW3l4q";
FacebookClient facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN);

    FacebookClient publicOnlyFacebookClient = new DefaultFacebookClient();

    User user = facebookClient.fetchObject("me", User.class);
    Page page = facebookClient.fetchObject("abc", Page.class);
    System.out.println(user.getId());
    FacebookType publishMessageResponse = facebookClient.publish(user.getId()+"/feed", FacebookType.class, Parameter.with("message", "hello"));

the above code is working fine, but the code below is not working in case of liking a comment.

    System.out.println("Published message ID: " + publishMessageResponse.getId());
    facebookClient.publish(publishMessageResponse.getId()+"/likes", FacebookType.class, null);

xception in thread "main" java.lang.NullPointerException
at     com.restfb.BaseFacebookClient.verifyParameterLegality(BaseFacebookClient.java:325)
at com.restfb.DefaultFacebookClient.makeRequest(DefaultFacebookClient.java:456)
at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:290)
at com.restfb.DefaultFacebookClient.publish(DefaultFacebookClient.java:298)
at javafbtest.JavaFbTest.main(JavaFbTest.java:40)
JN_newbie
  • 5,492
  • 14
  • 59
  • 97

1 Answers1

0

Why REST api? You should not use it, also the urls you're trying are not from the REST api but from the graph api.

If you are referring to the java SDK you are using, then maybe you should use something else, I'm not sure cuz I've never used it, I wrote my own.

To like a comment you'll need to have the comment id. Once you have that it's easy to like it using the graph api as it says in the documentation of the Comment object (under the likes connection):

Create

You can like a comment by issuing an HTTP POST request to COMMENT_ID/likes with the publish_stream permission. No parameters necessary.

Nitzan Tomer
  • 155,636
  • 47
  • 315
  • 299