public static void BatchRequest(string accessToken)
{
try
{
var fb = new FacebookClient(accessToken);
var result = (IList<object>)fb.Batch(
new FacebookBatchParameter("me"),
new FacebookBatchParameter(HttpMethod.Get, "me/friends", new { limit = 10 }));
var result0 = result[0];
var result1 = result[1];
// Note: Always check first if each result set is an exeption.
if (result0 is Exception)
{
var ex = (Exception)result0;
// Note: make sure to handle this exception.
throw ex;
}
else
{
var me = (IDictionary<string, object>)result0;
var name = (string)me["name"];
Console.WriteLine("Hi {0}", name);
}
Console.WriteLine();
if (result1 is Exception)
{
var ex = (Exception)result1;
// Note: make sure to handle this exception.
throw ex;
}
else
{
var friends = (IList<object>)((IDictionary<string, object>)result1)["data"];
Console.WriteLine("Some of your friends: ");
foreach (IDictionary<string, object> friend in friends)
{
Console.WriteLine(friend["name"]);
}
}
}
catch (FacebookApiException ex)
{
// Note: make sure to handle this exception.
throw;
}
}