Skip to main content Skip to main content Windows Experience Devices Windows Developer Microsoft Edge Windows Insider Microsoft 365 Microsoft 365 Azure Copilot Windows Surface XBOX Deals Small Business Support Windows Apps Outlook OneDrive Microsoft Teams OneNote Microsoft Edge Moving from Skype to Teams Computers Shop XBOX Accessories VR & mixed reality Certified Refurbished Trade-in for cash XBOX Game Pass Ultimate PC Game Pass XBOX games PC games Microsoft AI Microsoft Security Dynamics 365 Microsoft 365 for business Microsoft Power Platform Windows 365 Small Business Digital Sovereignty Azure Microsoft Developer Microsoft Learn Support for AI marketplace apps Microsoft Tech Community Microsoft Marketplace Software companies Visual Studio Microsoft Rewards Free downloads & security Education Gift cards Licensing Unlocked stories View Sitemap
July 14, 2015
Mobile

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#

[code language=”csharp”]
// 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);
}
}
}
[/code]

C++

[code language=”cpp”]// 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);
}
});
}
}[/code]

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:

Your Privacy Choices Opt-Out Icon Your Privacy Choices
Consumer Health Privacy Sitemap Contact Microsoft Privacy Manage cookies Terms of use Trademarks Safety & eco Recycling About our ads