July 14, 2015 3:30 pm

Windows SDK for Facebook

We’re pleased to announce a new open source library for integrating Facebook into your Windows apps. The Windows SDK for Facebook is geared towards app developers creating Universal Windows apps on both desktop and phone. The SDK supports universal Windows app for Windows Phone 8.1, Windows 8.1 or Windows 10. Using this library, you can easily integrate Facebook Authorization, Like, Graph and other Facebook functionality into your app. This library is also fully native so the CLR is not a dependency. Features included are:

  • Authorization
    • Login
    • Logout
    • Login Button
    • Profile Picture control
  • Dialogs
    • Feed dialog
    • Request dialog
  • Graph
    • Custom Stories
    • Post to user’s feed
    • Upload Photo
    • Like a Page/Object

Where to Get the SDK

The SDK can be found on GitHub: https://github.com/Microsoft/winsdkfb.

If you are developing a universal Windows app for Windows Phone 8.1, Windows 8.1 or Windows 10 and are currently using the Facebook .NET SDK (http://facebooksdk.net/), we recommend that you evaluate the new Windows SDK for Facebook for use in your app. The new Windows SDK features are listed on GitHub.

This new SDK carries forward the most popular capabilities of the existing .NET SDK. Should you identify any key features missing, please submit a feature request on the Windows SDK for Facebook GitHub repo.

Compilation Instructions

Compilation instructions for Windows apps are on the GitHub repo.

App Samples

Also included are sample projects that show how to integrate this library into your app. The sample projects show how to:

  • Log in
  • Display user information
  • Post to user timeline via feed dialog
  • Launch app request dialog to send requests to friends
  • Display the list of user’s likes

We have multiple samples on the GitHub repo. Below are some code snippets in C# and C++ showing how to do a login and get a user’s likes.

C#

// Get active session
FBSession sess = FBSession.ActiveSession;

// Add permissions required by the app
sess.AddPermission("public_profile");
sess.AddPermission("user_friends");
sess.AddPermission("user_likes");
sess.AddPermission("user_groups");
sess.AddPermission("user_location");
sess.AddPermission("user_photos");
sess.AddPermission("publish_actions");

// Login to Facebook 
FBResult result = await sess.LoginAsync();

if (result.Succeeded)
{
	// Login successful, fetch user likes
	GetUserLikes();
}
else
{
	// Login failed
	// Do work
}

public async void GetUserLikes()
{
	if (FBSession.ActiveSession.LoggedIn)
	{
		string graphPath = FBSession.ActiveSession.User.Id + "/likes";

		FBJsonClassFactory fact = new FBJsonClassFactory(
			(JsonText) = > MyFBPage.FromJson(JsonText));

		FBPaginatedArray _likes_likes = new FBPaginatedArray(graphPath, null, fact);
		FBResult result = await _likes.First();
		if (result.Succeeded)
		{
			IReadOnlyList<object> pages =
				(IReadOnlyList<object>)result.Object;

			AddLikes(pages);
		}
	}
}

C++

// Get active session
FBSession^ sess = FBSession::ActiveSession;

// Add permissions required by the app
sess->AddPermission("public_profile");
sess->AddPermission("user_friends");
sess->AddPermission("user_likes");
sess->AddPermission("user_groups");
sess->AddPermission("user_location");
sess->AddPermission("user_photos");
sess->AddPermission("publish_actions");

// Login to Facebook
create_task(sess->LoginAsync()).then([=](FBResult^ result)
{
	if (result->Succeeded)
	{
		// Login succeeded, fetch user likes
		GetUserLikes();
	}
	else
	{
		// Login failed
		// do work
	}
});

void GetUserLikes()
{
	FBSession^ sess = FBSession::ActiveSession;
	if (sess->LoggedIn)
	{
		String^ graphPath = sess->User->Id + L"/likes";
		FBJsonClassFactory^ fact =
			ref new FBJsonClassFactory([](String^ JsonText) -> Object^
		{
			return FBPageBindable::FromJson(JsonText);
		});

		Facebook::Graph::FBPaginatedArray^ _likes;
		_likes = ref new FBPaginatedArray(graphPath, nullptr, fact);
		create_task(_likes->First()).then([this](FBResult^ result)
		{
			if (result->Succeeded)
			{
				IVectorView<Object^>^ items = static_cast<IVectorView<Object^>^>
					(result->Object);

				AddLikes(items);
			}
		});
	}
}

We’d like to encourage you to try the Windows SDK for Facebook. And, if you have suggestions for other open source projects that would help you make great apps, please let us know in the comments. For more information about Microsoft’s involvement with open source, check out these sites:

Updated July 14, 2015 4:34 pm

Join the conversation

  1. Is there a way to use the actual Facebook app for authentication or do a feed post instead of showing an in-app-browser window with this library?

    • It is not currently in the SDK but would be possible to add. This feature would rely on the Facebook app implementing the fbconnect:// contract. Currently only the Facebook app for Windows Phone 8.1 supports this contract

    • The SDK NuGet package is not published to nuget.org at this time, but it may be built privately using our command-line build. We’re currently evaluating how best to provide prebuilt binaries for the SDK.

  2. There’s a Facebook in WinRT for WP on the plans?
    Or better: there’s a Universal Facebook for Windows 10?

  3. Every time I run the LoginCpp example this error occurs…
    Unable to find version ‘0.9.0’ of package ‘FBWinSDK’

  4. Hi, I have one question.
    When I compile the sdk, Visual Studio (2015) get an error. “The namespace Facebook doesn’t exist.”

    How can I to resolve this ?

  5. I’m trying to get this SDK to work with Unity, to do so it needs to be inside Unity’s Asset structure. I was thinking that the best way would be to create a DLL with the SDK in for use within Unity.

    I’m running into problems though, and keep finding it difficult to solve them, is anyone able to help with some pointers on how to do it?

    • Even in the samples provided with the SDK download, I can’t use “using Facebook”, as the namespace can’t be found.

      The references have these were needed:
      FBWinSDK\FBWinSDK\FBWinSDK.Windows\FBWinSDK.Windows.vcxproj
      FBWinSDK\FBWinSDK\FBWinSDK.WindowsPhone\FBWinSDK.WindowsPhone.vcxproj

  6. Hi,

    I’ve used this to build a plugin for Unity and its working great, so thanks for the awesome work.

    I’m wondering if there is a way to auto log a user back in again? Looking at the implementation from Facebook, it uses cached data to recreate the session, but I haven’t seen anything similar with this SDK. Is there a way to do it?