facebook-csharp-sdk/facebook-csharp-sdk — pull request #219 by prabirshrestha (2012-11-13 01:07:15+00:00)
Title: added FacebookClient.Subscription to verify get and post subscription

Added some helper methods to deal with RealTime subscription apis.

* added `FacebookClient.SubscriptionVerifyToken`
* added `FacebookClient.VerifyGetSubscription` void method.
* added `FacebookClient.VerifyPostSubscription` method. (returns object which is a dynamic json)

There additional overloads so you can pass `verify_token` or `app secret` in parameter instead of setting it in the `FacebookClient` property.

Here is a full example on how to use it in asp.net web forms. subscription.ashx.cs
MVC could use `ActionFilters`.

```c#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using Facebook;

namespace WebApplication
{
///

/// Summary description for subscription
///

///
/// InMemoryNoticiationStore, ?list=true and ?clear=true is for debugging purpose
///
public class subscription : IHttpHandler
{
private static readonly IList InMemoryNoticiationStore = new List();

public void ProcessRequest(HttpContext context)
{
var fb = new FacebookClient
{
AppSecret = "....",
SubscriptionVerifyToken = "...",
};

var request = context.Request;
var response = context.Response;

if (request.QueryString["list"] == "true")
{
response.Write(string.Join(",", InMemoryNoticiationStore));
return;
}
else if (request.QueryString["clear"] == "true")
{
InMemoryNoticiationStore.Clear();
return;
}

if (request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase))
{
try
{
// VerifyGetSubscription will throw exception if verification fails.
fb.VerifyGetSubscription(
request.Params["hub.mode"],
request.Params["hub.verify_token"],
request.Params["hub.challenge"]);

response.Write(request.Params["hub.challenge"]);
}
catch (Exception ex)
{
InMemoryNoticiationStore.Add(ex.StackTrace);
}
}
else
{
try
{
// VerifyPostSubscription will throw exception if verification fails.
dynamic result = fb.VerifyPostSubscription(
request.Params["HTTP_X_HUB_SIGNATURE"],
new StreamReader(request.InputStream).ReadToEnd());

// result is a json object that was sent by Facebook
// for now just call ToString() so it returns the json string
string jsonString = result.ToString();

// Process the result
// for this demo we will just add it to the list
InMemoryNoticiationStore.Add(jsonString);
}
catch (Exception ex)
{
InMemoryNoticiationStore.Add(ex.StackTrace);
}
}
}

public bool IsReusable
{
get
{
return false;
}
}
}
}
```

Currently these are private in FacebookClient. Should me these constants public?

```c#
private const string SubscriptionHttpXHubSigntureKey = "HTTP_X_HUB_SIGNATURE";

private const string SubscriptionHubChallengeKey = "hub.challenge";
private const string SubscriptionHubVerifyTokenKey = "hub.verify_token";
private const string SubscriptionHubModeKey = "hub.mode";
```