0

根据https://developers.facebook.com/docs/reference/api/,我们可以点赞评论。我可以发表评论,但我不知道如何点赞评论。我在下面写了一个代码来确认语法是否正确,而且它也给出了一个例外。

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"));

上面的代码工作正常,但下面的代码在喜欢评论的情况下不起作用。

    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)
4

1 回答 1

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.

于 2012-05-07T09:34:35.373 回答