10

我想在我的应用程序中实现“喜欢”和“评论”功能。我使用了这段代码:

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

我如何以及在哪里调用这些方法以使其工作?

4

1 回答 1

3

请确保先决条件设置正确。具体检查步骤 4 的中间部分,以确保您使用调试密钥库正确生成了密钥哈希。

否则下面的代码应该会有所帮助

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;
        }
    }
于 2014-01-22T00:21:38.120 回答