Pages

Friday, March 8, 2013

Tiny C# Facebook Batch Request Connector

Why

Recently, I have had the great joy of working on some Facebook events integration. The issue was that the requests were sent one at a time. Facebook batch request was the answer.

The existing code base is C#. I can use the popular C# Facebook SDK at http://csharpsdk.org/, but it might be overly complex for the project.

So I wrote this little C# Facebook Batch Request connector: https://github.com/jhuangsoftware/FacebookBatchRequest


Can It Return Html?

Sure. Extend current project to covert returned JSON to HTML. Alternatively, use the current connector as part of your project, which actually converts JSON to HTML


Sample Code: Inline ASPX Code

<%@ Import Namespace="FacebookBatchRequestLib" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%
    FacebookBatchRequest FBBatchRequestObj = new FacebookBatchRequest("XYZ|XYZ");
    FBBatchRequestObj.AddBatchUrl(RequestMethod.GET, "something1/events?access_token=XYZ|XYZ&fields=name,description,start_time,end_time,location,id&since=2013-03-08&limit=15");
    FBBatchRequestObj.AddBatchUrl(RequestMethod.GET, "something2/events?access_token=XYZ|XYZ&fields=name,description,start_time,end_time,location,id&since=2013-03-08&limit=15");

    List RetJSONs = FBBatchRequestObj.Send();
%>

Just remember to drop FacebookBatchRequestLib.dll into the bin folder


Sample Code: Windows Application

Included in the GitHub project. Check it out.

No comments:

Post a Comment