user2709885
user2709885

Reputation: 423

How can I get all the likes of a Facebook user according to a category in Android?

Hi I am stuck on a very small problem. I am making an Android app and I have integrated it with FB. I would like to get a list of all pages of a particular category that a Facebook user has liked ?

This is the code I have written so far :

        new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            user_id+"/likes/",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {

                @Override
                public void onCompleted(GraphResponse graphResponse) {
                    Log.d("check",graphResponse.toString());
                }
            }).executeAsync();

This is returning a JSON object of all liked pages. Each FB page has a field called category. For instance, category is clothing. Now how can I only get clothing pages that a user has liked ? Thanks

Upvotes: 2

Views: 445

Answers (2)

Harshal Bhatt
Harshal Bhatt

Reputation: 731

I used following code to get pages liked by user only in music category,

Request:

 GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/me/music",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "link");
request.setParameters(parameters);
request.executeAsync();

Response :

{
  "data": [
    {
      "link": "https://www.facebook.com/Vh1Supersonic/",
      "id": "557785804313645"
    },
    {
      "link": "https://www.facebook.com/onedirectionmusic/",
      "id": "121930497861753"
    },
    {
      "link": "https://www.facebook.com/seanpaul/",
      "id": "10161539667"
    },
    {
      "link": "https://www.facebook.com/officialflo/",
      "id": "53856904324"
    },
    {
      "link": "https://www.facebook.com/seankingston/",
      "id": "5128508749"
    },
    {
      "link": "https://www.facebook.com/DavidGuetta/",
      "id": "7619396355"
    },
    {
      "link": "https://www.facebook.com/TaylorSwift/",
      "id": "19614945368"
    },
    {
      "link": "https://www.facebook.com/pitbull/",
      "id": "95051637400"
    },
    {
      "link": "https://www.facebook.com/michaeljackson/",
      "id": "19691681472"
    },
    {
      "link": "https://www.facebook.com/usher/",
      "id": "6564142497"
    },
    {
      "link": "https://www.facebook.com/AKON/",
      "id": "16929140023"
    },
    {
      "link": "https://www.facebook.com/linkinpark/",
      "id": "8210451787"
    }
  ],
  "paging": {
    "cursors": {
      "before": "NTUDK3Nzg1ODA0MzEzNjQ1",
      "after": "ODIxMDQ1MOM2Tc4NwZDZD"
    }
  }
}

Upvotes: 0

andyrandy
andyrandy

Reputation: 74014

You can´t filter with the Graph API, at least not right now. You will have to do that on your own after getting all entries.

Upvotes: 1

Related Questions