C# v5 async extensions for Facebook C# SDK
C#
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
libs/Async + AsyncCtpLibrary May 9, 2011
samples
src
.gitignore
LICENSE.txt
README.md + updated README.md Oct 17, 2011

README.md

Facebook.Extensions.Tasks is no longer under development. These XTaskAsync() methods are now part of the core Facebook C# SDK starting from v5.3

Facebook.Extensions.Tasks

Overview

This library takes the asynchorous programming with Facebook C# SDK to the next level by adding extension methods to FacebookClient and FacebookOAuthClient which returns Task<object>

Requirements

Getting Started

Reference Facebook.Extensions.Tasks.dll which adds extension methods to FacebookClient and FacebookOAuthClient. To prevent conflicts from existing async methods, these extension methods start with HttpMethod type and ends with TaskAsync( ... ). Even though the dll name is "Facebook.Extensions.Tasks.dll" these extension methods are under the "Facebook" namespace.

Extension methods available for FacebookClient:

GetTaskAsync( ... )
PostTaskAsync( ... )
DeleteTaskAsync( ... )

Extension methods available for FacebookOAuthClient:

GetApplicationAccessTokenTaskAsync( ... )
ExchangeCodeForAccessTokenTaskAsync( ... )

Samples

Full samples can be found under the "samples" folder in the source code.

Using with Task Parallel Library (TPL)

private static void ExecuteAsyncMethod()
{
	var fb = new FacebookClient();
	var task = fb.GetTaskAsync("/4");

	task.ContinueWith(
		t =>
		{
			if (t.Exception == null)
			{
				dynamic result = t.Result;
				Console.WriteLine("Name: {0}", result.name);
			}
			else
			{
				Console.WriteLine("error occurred");
			}
		});
}

Note: If you are running the above code under .NET 4.0, you don't need to reference the Async libraries as Task Parallel Library (TPL) comes bundled with .NET 4.0. For Silverlight and Windows Phone 7 Async libraries (AsyncCtpLibrary_Silverlight.dll or AsyncCtpLibrary_Phone.dll) must be referenced as TPL is not present.

Using with async and await

private async static void ExecuteAsyncMethod()
{
	var fb = new FacebookClient();

	try
	{
		dynamic result = await fb.GetTaskAsync("/4");

		Console.WriteLine("Name: {0}", result.name);
	}
	catch (FacebookApiException ex)
	{
		Console.WriteLine(ex.Message);
	}
}

Note: Reference the appropriate Async libraries (AsyncCtpLibrary.dll or AsyncCtpLibrary_Silverlight.dll or AsyncCtpLibrary_Phone.dll). You need to reference AsyncCtpLibrary.dll for .NET 4.0 also in this case unlike the example with TPL.

License

Facebook.Extensions.Tasks is intended to be used in both open-source and commercial environments. It is licensed under Microsoft Public License (Ms-PL).