Let’s see the steps.
Before starting you will have to go to the Facebook Developer Portal and create a new app for windows platform then get a Facebook App ID like the following screen.
Go to https://developers.facebook.com and login with your account.
Create new app.
It will show the popup screen,
Then fill the details of your app.
Next add the platform “Windows App” by selecting "Settings" from the menu on the left.
Click on the "Basic" tab.
Click on "Add Platform" and select "Windows App".
Then fill the windows app store id. We can get the windows store app id using the following code,
- string SID = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();
Next Enable Client OAuth and Web OAuth Login,
Note your APP ID from dashboard
Now create your new windows 10 universal app and add the face book SDK from NuGet like the following screen.
Right Click on reference in you project then select manage nuget package search “winsdkfb” and install it.
Now go to you design page “MainPage.XAML” and add the following xaml namespace,
- xmlns:fb="using:winsdkfb"
- xmlns:udi="using:winsdkfb.winsdkfb_uwp_XamlTypeInfo"
Next add the face book login button it’s comes with Facebook SDK.
- <fb:FBLoginButton x:Name="login" Click="login_Click"></fb:FBLoginButton>
Now go to your code behind page and add the following code,
- private readonly string[] requested_permissions =
- {
- "public_profile",
- "email",
- "user_friends",
- "publish_actions"
- };
Replace your window store app id and face book app id.
- private async void login_Click(object sender, RoutedEventArgs e)
- {
- FBSession clicnt = FBSession.ActiveSession;
- clicnt.WinAppId = "your app id";
- clicnt.FBAppId = "fb app id";
- FBPermissions permissions = new FBPermissions(requested_permissions);
- FBResult result = await clicnt.LoginAsync(permissions);
- if (result.Succeeded)
- {
- }
- else
- {
-
- }
- }
Now run the app and see the excepted output like the following screen.
For more information on Windows 10 UWP, refer to my e-book:
Read more articles on Universal Windows Platform: