3

我想用它的 id 获取给定页面的点赞数。

这是我想用 facebook-android-sdk 翻译的图形 api 请求。

我不知道怎么做。如果我尝试,我会收到错误:

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

2 回答 2

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

该请求将在下面的图形 api request中进行翻译。

于 2013-04-24T08:45:36.863 回答
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”字段。

于 2014-04-16T13:21:42.033 回答