本文整理汇总了C#中Facebook.FacebookClient.BatchAsync方法的典型用法代码示例。如果您正苦于以下问题:C# FacebookClient.BatchAsync方法的具体用法?C# FacebookClient.BatchAsync怎么用?C# FacebookClient.BatchAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook.FacebookClient
的用法示例。
在下文中一共展示了FacebookClient.BatchAsync方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BatchRequestAsyncExample
private void BatchRequestAsyncExample()
{
var fb = new FacebookClient(_accessToken);
// since batch request is actually a POST request internally,
// make sure to add the event handler for PostCompleted.
fb.PostCompleted += (o, e) =>
{
// incase you support cancellation, make sure to check
// e.Cancelled property first even before checking (e.Error!=null).
if (e.Cancelled)
{
// for this example, we can ignore as we don't allow this
// example to be cancelled.
// you can check e.Error for reasons behind the cancellation.
var cancellationError = e.Error;
}
else if (e.Error != null)
{
// error occurred
this.BeginInvoke(new MethodInvoker(
() =>
{
//MessageBox.Show(e.Error.Message);
}));
}
else
{
// the request was completed successfully
// now we can either cast it to IDictionary<string, object> or IList<object>
// depending on the type. or we could use dynamic.
dynamic result = e.GetResultData();
// note: batch requests doesn't support generic versions of e.GetResultData<T>()
// make sure to be on the right thread when working with ui.
this.BeginInvoke(new MethodInvoker(
() =>
{
// always remember to check individual errors for the batch requests.
if (result[0] is Exception)
MessageBox.Show(((Exception)result[0]).Message);
dynamic first = result[0];
string name = first.name;
// note: incase the omit_response_on_success = true, result[x] == null
// for this example just comment it out
//if (result[1] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[2] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[3] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[4] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[5] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[6] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
//if (result[7] is Exception)
// MessageBox.Show(((Exception)result[1]).Message);
}));
}
};
fb.BatchAsync(new[]{
new FacebookBatchParameter { HttpMethod = HttpMethod.Get, Path = "/4" },
new FacebookBatchParameter(HttpMethod.Get, "/me/friend", new Dictionary<string, object> { { "limit", 10 } }), // this should throw error
new FacebookBatchParameter("/me/friends", new { limit = 1 }) { Data = new { name = "one-friend", omit_response_on_success = false } }, // use Data to add additional parameters that doesn't exist
new FacebookBatchParameter { Parameters = new { ids = "{result=one-friend:$.data.0.id}" } },
new FacebookBatchParameter("{result=one-friend:$.data.0.id}/feed", new { limit = 5 }),
new FacebookBatchParameter().Query("SELECT name FROM user WHERE uid="), // fql
new FacebookBatchParameter().Query("SELECT first_name FROM user WHERE uid=me()", "SELECT last_name FROM user WHERE uid=me()") // fql multi-query
//,new FacebookBatchParameter(HttpMethod.Post, "/me/feed", new { message = "test status update" })
});
}