K232
K232

Reputation: 1069

Check whether facebook user likes my app

I've read several sources now but did not find a solution: I'm using Facebook C# SDK with ASP.net 4 and VB.net 2010. I have a Facebook Canvas application. I'm using Canvas Auth.Authorize and it works fine. Now I want to know whether the currently logged in user already likes my app. How could I do that?

But the Facebook Plugin is able to differ whether the current user likes my app or not, so I'm quite optimistic that there is a way which I just did not find yet.

Many thanks!

Upvotes: 0

Views: 757

Answers (1)

Nate Totten
Nate Totten

Reputation: 8932

You can use the graph API to call the users likes. Instead of requesting all of the likes simply request the single one you want.

https://graph.facebook.com/userId/likes/appId

If you the user has liked the page the result will return details about the page. For example:

{
  "data": [
    {
      "name": "Microsoft Office Web Apps", 
      "category": "Software", 
      "id": "121883824529155", 
      "created_time": "2012-03-14T06:48:47+0000"
    }
  ], 
  "paging": {
    "next": "https://graph.facebook.com/me/likes/121883824529155?format=json&limit=5000&offset=5000&__after_id=121883824529155"
  }
}

If the user has not liked the page you will receive empty data.

{
  "data": [
  ]
}

With the Facebook C# SDK you would make this request as follows:

var client = FacebookClient("access_token_here");
dynamic result = client.Get('/me/appId');
if (result.data.Length == 1) {
  // User has liked page
}

Upvotes: 2

Related Questions