取Facebook的API通知3.0 [英] Fetch Facebook notifications API 3.0

查看:168
本文介绍了取Facebook的API通知3.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的Andr​​oid应用程序,我需要能够定期获取用户有多少未读的通知已经和我的应用程序显示这一点。

I'm developing an app for Android and I need to be able to periodically fetch how many unread notifications a user has and display this in my app.

我相信这不是直线前进的3.0的API中。

I believe this is not straight forward in the 3.0 API.

有人能说明一下最好的方法为这个?

Can somebody please explain the best method for this?

我用这code:

Request notificationsRequest = Request.newGraphPathRequest(
        Session.getActiveSession(), "/me/notifications",
        new Request.Callback() {

            @Override
            public void onCompleted(Response response) {
                GraphObject object = response.getGraphObject();
                if (object != null) {
                    notifications = object.getProperty("data")
                            .toString();
                } else {
                    notifications = "Notifications returns null";
                }
            }
        });

但它的返回

推荐答案

您必须包括include_read和真。
你可以这样说:

You must include "include_read" and "true". You can do it like this:

if (object != null) {

    try {

    JSONObject jsonObject = object.getInnerJSONObject().getJSONObject("summary");
    int notificationsUnread = jsonObject.getInt("unseen_count");

    Log.i("FB notificationsSummary", jsonObject + "");

    } catch (JSONException e) {             
        // TODO Auto-generated catch block
        e.printStackTrace();                        
    }


    Bundle notificationParams = new Bundle();
    notificationParams.putString("include_read", "true");
    yourRequest.setParameters(notificationParams);

    yourRequest.execute();
}

这篇关于取Facebook的API通知3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆