简体   繁体   中英

Not getting all notifications from Facebook SDK, Graph-API

I am making an application and I need to get all new notifications from Facebook. I succesfully login and get manage_notifications permission to my App. This piece of code succesfuly load JSON string from facebook.

Session session = Session.openActiveSessionFromCache(ctx);
    if (session != null && session.isOpened()) {
        Request notificationsRequest = Request.newGraphPathRequest(
                session, "/me/notifications",
                new Request.Callback() {

                    @Override
                    public void onCompleted(Response response) {
                        GraphObject object = response
                                .getGraphObject();
                        if (object != null) {
                            notificationsNewString = object
                                    .getInnerJSONObject()
                                    .toString();

                            try {
                                notificationsOldString = saver.getJsonFromInternalCache();
                            } catch (IOException e) {
                                notificationsOldString = null;
                            }
                            try {
                                compareOldAndNewData();
                            } catch (ParseException e) {
                                e.printStackTrace();
                            }

                            createNotif();

                        } else {
                            notificationsNewString = "Notifications returns null";
                        }

                    }
                });
        Request.executeBatchAndWait(notificationsRequest);
    } else {
        Log.i("TAGTAG", "Session not open!");
    }

But some people have difficulties with app, because Facebook dont send in json all new notifications. Especially notification if someone comments on status that they comment. (On Facebook it is marked like a new notification, but json is empty).

Its about some permissions or it is bug?

Thanks.

I found another way. I will post it in case somebody finds it helpful

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
if (state.isOpened()) {
    InboxMessage.setVisibility(View.VISIBLE);

    new Request(session,"/me/notifications", null,HttpMethod.GET,new Request.Callback() {

                public void onCompleted(Response response) {
                    GraphObject object = response.getGraphObject();
                        if (object != null) {
                            InboxMessage.setText(object.getProperty("data").toString());
                        } else {
                            InboxMessage.setText("Notifications returns null");
                        }
                }
            }
        ).executeAsync();
} else {
    InboxMessage.setVisibility(View.INVISIBLE);
    Log.i(TAG, "Logged out...");
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM