如何通过Android喜欢Facebook帖子

时间:2014-03-06 16:26:57

标签: android facebook facebook-like

我使用这种方法喜欢帖子,问题是我总是把NullPointer作为Facebook响应。乳清是不是发生了?

编辑:这是我现在正在使用的方法......发生了同样的事情。

public void likePost (final Bundle params){

    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
          SessionState state = session.getState();

          if (state.isOpened()){

                if (session.isPublishPermission("publish_stream")){

                    Request likeRequest = new Request(session, params.getString("object")+ "/likes", null, HttpMethod.POST, new Request.Callback() {

                     @Override
                     public void onCompleted(Response response) {
                            Log.i("LIKE_METHOD", response.toString());
                     }
                        });
                        Request.executeBatchAndWait(likeRequest);
                }else {

                    session.requestNewPublishPermissions(new NewPermissionsRequest(this, Arrays.asList("publish_stream")));

                    Request likeRequest = new Request(session, params.getString("object")+ "/likes", null, HttpMethod.POST, new Request.Callback() {

                         @Override
                         public void onCompleted(Response response) {
                                Log.i("LIKE_METHOD", response.toString());
                         }
                            });
                            Request.executeBatchAndWait(likeRequest);

                }

            }

        }
        else {
           Session.openActiveSession(this, true, new StatusCallback() {
                @Override
                public void call(Session session, SessionState state, Exception exception) {

                    if (state.isOpened()){

                        if (session.isPublishPermission("publish_stream")){

                            Request likeRequest = new Request(session, params.getString("object")+ "/likes", null, HttpMethod.POST, new Request.Callback() {

                             @Override
                             public void onCompleted(Response response) {
                                    Log.i("LIKE_METHOD", response.toString());
                             }
                                });
                                Request.executeBatchAndWait(likeRequest);
                        }else {

                            session.requestNewPublishPermissions(new NewPermissionsRequest(getParent(), Arrays.asList("publish_stream")));

                            Request likeRequest = new Request(session, params.getString("object")+ "/likes", null, HttpMethod.POST, new Request.Callback() {

                                 @Override
                                 public void onCompleted(Response response) {
                                        Log.i("LIKE_METHOD", response.toString());
                                 }
                                    });
                                    Request.executeBatchAndWait(likeRequest);

                        }

                    }

                }
            });
        }
    }

这是该方法的回应:

  

03-06 15:55:08.532:D / LIKE_METHOD(16686):{响应:responseCode:200,graphObject:null,错误:{HttpStatus:-1,errorCode:-1,errorType:null,errorMessage:java .lang.NullPointerException},isFromCache:false}   pe:null,errorMessage:java.lang.NullPointerException},isFromCache:false}

0 个答案:

没有答案