0

I'm attempting to retrieve the total number of likes for a selected Facebook Page POST

According to this page:

How to get Likes Count when searching Facebook Graph API with search=xxx

I've tried to refer to the answers in that post and to build my code based on that.Here's the current code that I have based on it

private void totalLikes(String post_id){
    Bundle bun = new Bundle();
    bun.putString("summary","true");
    new Request(Session.getActiveSession(), post_id+"/likes/",bun, HttpMethod.POST,
            new Request.Callback() {

                @Override
                public void onCompleted(Response response) {
                    Toast.makeText(getBaseContext(),String.valueOf(response),Toast.LENGTH_SHORT).show();

                }
}).executeAsync();
}

Unfortunately the response given is not what was expected,I was thinking that it could be due to my Bundle parameters.So I would like to know what are the actual bundle parameters I should be putting for the code?Thank you for the help :)!

Community
  • 1
  • 1
Arvind Dinivra
  • 357
  • 1
  • 3
  • 14

1 Answers1

0

In your Bundle string addition, try changing it to bun.putString("fields","likes.summary(true)"); and change the graph path to just the post_id. There should end up being a "summary" field in the response after that.

EDIT: Here's another method that might work better with permissions.

Graph path: post_id + "/likes"

with

bun.putString("include_summary", "true");

I tried messing around in the explorer and couldn't get it to work, but you might have better luck.

Wenger
  • 989
  • 2
  • 12
  • 35
  • Thank you for the prompt reply.It seems that I'm doing something wrong.The code you've provided works perfect!But it seems that my created app requires "Manage Pages" permission.From this,I'm assuming that the app thinks that I want to get the **total summary likes for a post of page that I own**.I'm trying to retrieve the total likes of selected post for a page that I do not own,is there any possible way to do that?A huge thank you once again :) – Arvind Dinivra Jun 04 '14 at 13:49
  • Thank you for the edit.It seems that I was using **HttpMethod.POST** instead of **HttpMethod.GET** for my API query.That was why I received the permissions request.My apologies for my careless mistake.Thank you once again for the help :) – Arvind Dinivra Jun 05 '14 at 08:22
  • Ahhhh that'll do it! Didn't notice that. – Wenger Jun 05 '14 at 12:29