Facebook的Android SDK中如何让喜欢的数量对于一个给定页面(Facebook and

2019-08-31 22:13发布

我想获得喜欢的号码,以便与它的ID给定的页面。

这里是图形API请求 ,我想与Facebook的Android的SDK翻译。

我想不出如何做到这一点。 我得到的错误,如果我尝试:

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

Answer 1:

这里是要调用的方法:

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请求 。



Answer 2:

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

你会在HACE JSON响应字段“TOTAL_COUNT”。



文章来源: Facebook android sdk how to get the number of likes for a given page