Facebook android sdk如何获得给定页面的喜欢数量

时间:2013-04-23 12:54:22

标签: android facebook facebook-graph-api facebook-android-sdk

我想获得具有id的给定页面的喜欢数量。

这是我想用facebook-android-sdk翻译的graph api request

我无法想象如何制作它。如果我尝试,我会收到错误:

Bundle params = new Bundle();
params.putString("fields", "likes");
Request request = new Request(session,"104249301622", params, HttpMethod.GET, new Request.Callback() {  
    @Override
    public void onCompleted(Response response) {
        JSONObject res = response.getGraphObject().getInnerJSONObject();
        System.out.println(res);
    }
});

2 个答案:

答案 0 :(得分:4)

以下是调用方法:

Session session = Session.getActiveSession();
Bundle params = new Bundle();
params.putString("id", "104249301622");
params.putString("fields", "likes");
Request request = new Request(session, "search", params, HttpMethod.GET, new Request.Callback() {

    @Override
    public void onCompleted(Response response) {
        try {
            JSONObject res = response.getGraphObject().getInnerJSONObject().getJSONArray("data").getJSONObject(0);
            numberOfLikes = res.getInt("likes");
        } catch (Exception e) {
        }
    }
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();

请求将在以下graph api request中翻译。

答案 1 :(得分:1)

在facebook sdk 3.8

Bundle b = new Bundle();
    b.putBoolean("summary", true);


    new Request(
            session,
            id + "/likes",
            b,
            HttpMethod.GET,
            new Request.Callback() {
                public void onCompleted(Response response) {
                                    String s=response.toString();                   
                                 }
            }
    ).executeAsync();

你将在Json的回应中占据“total_count”字段。