Facebook.FacebookClient.Batch C# (CSharp) Method

Batch() public method

Makes a batch request to the Facebook server.
public Batch ( ) : object
return object
        public virtual object Batch(params FacebookBatchParameter[] batchParameters)
        {
            return Batch(batchParameters, null);
        }

Same methods

FacebookClient::Batch ( FacebookBatchParameter batchParameters, object parameters ) : object

Usage Example

Esempio n. 1
0
        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;
            }
        }
All Usage Examples Of Facebook.FacebookClient::Batch