根据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)