Facebook android sdk how to get the number of likes for a given page

烂漫一生 提交于 2019-12-01 09:26:02

Here is the method to call :

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

The request will be translated in the following graph api request.

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

And you will hace the field "total_count" in the Json response.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!