Integrate Facebook Login In Windows 10 Universal App

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.

app

It will show the popup screen,

screen

Then fill the details of your app.

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".

Windows

Then fill the windows app store id. We can get the windows store app id using the following code,

  1. string SID = WebAuthenticationBroker.GetCurrentApplicationCallbackUri().ToString();  
app

Next Enable Client OAuth and Web OAuth Login,

Login

Note your APP ID from dashboard

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.

install

Now go to you design page “MainPage.XAML” and add the following xaml namespace,

 

  1. xmlns:fb="using:winsdkfb"  
  2. xmlns:udi="using:winsdkfb.winsdkfb_uwp_XamlTypeInfo"  
Next add the face book login button it’s comes with Facebook SDK.
  1. <fb:FBLoginButton x:Name="login" Click="login_Click"></fb:FBLoginButton>  
Now go to your code behind page and add the following code,
  1. private readonly string[] requested_permissions =  
  2. {  
  3. "public_profile",  
  4. "email",  
  5. "user_friends",  
  6. "publish_actions"  
  7. };  
Replace your window store app id and face book app id.
  1. private async void login_Click(object sender, RoutedEventArgs e)  
  2. {  
  3. FBSession clicnt = FBSession.ActiveSession;  
  4. clicnt.WinAppId = "your app id";  
  5. clicnt.FBAppId = "fb app id";  
  6. FBPermissions permissions = new FBPermissions(requested_permissions);  
  7. FBResult result = await clicnt.LoginAsync(permissions);  
  8. if (result.Succeeded)  
  9. {  
  10. }  
  11. else  
  12. {  
  13.   
  14. }  
  15. }  
Now run the app and see the excepted output like the following screen.

output

For more information on Windows 10 UWP, refer to my e-book: 
Read more articles on Universal Windows Platform:


Similar Articles