Quantcast
Channel: Category Name
Viewing all articles
Browse latest Browse all 10804

Windows SDK for Facebook

$
0
0

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
…
}

…

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 pages =
				(IReadOnlyList)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
…
	}
});

…

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^ items = static_cast^>
					(result->Object);

				AddLikes(items);
			}
		});
	}
}

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
…
	}
});

…

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^ items = static_cast^>
					(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:


Viewing all articles
Browse latest Browse all 10804

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>