【问题标题】:Fetch Facebook notifications API 3.0获取 Facebook 通知 API 3.0
【发布时间】:2013-03-13 21:06:58
【问题描述】:

我正在开发一款适用于 Android 的应用,我需要能够定期获取用户有多少未读通知并将其显示在我的应用中。

我认为这在 3.0 API 中并不简单。

有人可以解释一下最好的方法吗?

我正在使用此代码:

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

但它正在返回null

【问题讨论】:

    标签: java android facebook facebook-graph-api


    【解决方案1】:

    您必须包含“include_read”和“true”。 你可以这样做:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-21
      • 2015-07-31
      • 1970-01-01
      • 2013-04-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多