1

The problem is that 1) Facebook seems so fluid with how it allows developers to interact with it (FBML, iFrame, different versions of SDKs) and 2) Everything I find is either PHP or Javascript and I have NO experience with those. What I am trying to do seems sooo simple, and I can't believe there isn't an easy way to do this.

What I have:

  • I used Visual Studio 2010 to create a simple web application (asp.net/C#) that asks the user for some info (first name, last name, email, etc.). I have a button on there called "Submit" that, when clicked, saves the entered data into a database. I have this hosted on GoDaddy (I know, I know...heh) and it works just fine. No problem here.

  • I created a "Facebook App" that uses the iFrame thingy so that basically I have a new tab on Facebook that displays my web app mentioned above. This works fine too. The tab is there, the web app is there, and users can enter the data and it is saved to the database. No problem here.

What I WANT:

  • I want the web app (the thing displayed by the facebook app) to only show the data entry part if the user currently "likes" the facebook entity. I DO NOT want to have to ask permission. I just want to know if they are a fan of the company's facebook "page" that has this app. So I need two things here, shown in my pseudo code below:

Part 1 (check if user is already a fan):

If (user is fan)
{
    Show data entry area (unhide it)
}
else
{
    Show "Click the like button to see more options"
}

Part 2 (listen for "like" event)

WhenLikeButtonPressed()
{
    Show data entry area (unhide it)
}

I've seen stuff about "visible to connection", C# sdk, edge.create, etc. but I just can't make heads or tails of it. I don't mind putting in Javascript or PHP if someone could please give me exact, "Fan Gate for Dummies" steps. Please, I'm going crazy over here :-(

casperOne
  • 73,706
  • 19
  • 184
  • 253
ghostatron
  • 2,620
  • 23
  • 27
  • possible duplicate? http://facebook.stackoverflow.com/questions/6595259/fans-only-content-in-facebook-with-asp-net-c-sdk/ – jches Sep 19 '11 at 22:17

1 Answers1

0

The key is is the signed_request that Facebook posts to your app when the user accesses the page. It contains the data on whether or not the user likes the page. You shouldn't need to worry about catching edge events on an actual tab FB page as it get's reloaded when the user likes/unlikes the page.

You'll need to decode the signed request with your app secret to get the like info. There are examples provided for PHP but I'm sure with a little google help you can find decode info for the signed_request for asp.net/c#.

Here's the php decode for reference:

function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);

if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
  error_log('Unknown algorithm. Expected HMAC-SHA256');
  return null;
}

// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
  error_log('Bad Signed JSON signature!');
  return null;
}

return $data;
}

function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}

and the link https://developers.facebook.com/docs/authentication/signed_request/ the like info will be contained in the page variable

Dustin Nielson
  • 1,264
  • 1
  • 8
  • 8
  • Very good to know I don't have to worry about catching the like event. Thanks! I will try some searches for dealing with signed_request with c#. Sometimes you just have to know WHAT to look for. I spent a good 3 hours just to figure out that people often refer to what I am trying to do as "fan gate" or "like gate". ;-) – ghostatron Sep 19 '11 at 21:05
  • @conarch this answer has C# code you can use to decode the `signed_request` parameter: http://facebook.stackoverflow.com/questions/6595259/fans-only-content-in-facebook-with-asp-net-c-sdk/7403427#7403427 – jches Sep 19 '11 at 22:19
  • My client ended up not wanting to do this, but Dustin's answer looked promising so I will mark it as the answer. – ghostatron Oct 10 '11 at 22:09
  • Signed request parser in official API: https://github.com/facebook-csharp-sdk/facebook-csharp-sdk/blob/master/Source/Facebook/FacebookClient.SignedRequest.cs – dahlbyk Jul 05 '12 at 01:02