如何使用Android Facebook SDK整合“喜欢”和“评论”功能?

前端之家收集整理的这篇文章主要介绍了如何使用Android Facebook SDK整合“喜欢”和“评论”功能?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想在我的应用程序中实现“喜欢”和“评论功能.我用这段代码
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(),bundle,new Callback() {
    @Override
    public void onCompleted(Response response) {
        Log.i(TAG,"Success!");
    }
});
    Request.executeBatchAsync(request);
 }

哈佛,我在哪里可以称这些方法让他们工作?

解决方法

请确保 prerequisites设置正确.具体检查步骤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;
        }
    }
原文链接:https://www.f2er.com/android/312019.html

猜你在找的Android相关文章