Google WindowsPhone Store 8.1 : FaceBook Integration Sample (C#-Xaml) | SubramanyamRaju Xamarin & Windows App Dev Tutorials

Wednesday, 31 December 2014

WindowsPhone Store 8.1 : FaceBook Integration Sample (C#-Xaml)

Introduction:

In previous article i was explained the concept of facebook login support for windowsphone 8.0,Now this article will show you how to easily integrate Facebook to your Windows Phone Store 8.1 application.
This topic contains the following sections:
  • Installation of Facebook SDK
  • Linking App with facebook.
  • Work with Facebook Login Page.
  • Post status message on FaceBook Wall.
  • Logout from Facebook Page.
Why FaceBook Integration?
Facebook users increasingly rely on their Facebook identity to access apps, play games with friends, share playlists or comment in a forum. As a developer, you may also rely on Facebook Login to tap into the Facebook social graph to enhance your app’s experience, enable new scenarios and open up the app to new customers, resulting in better revenue opportunities.

Requirements:

  • This sample is targeted for windowsphone store 8.1 OS,So make sure you’ve downloaded and installed the Windows Phone 8.1 SDK. For more information, see Get the SDK.
  • I assumes that you’re going to test your app on the Windows Phone emulator. If you want to test your app on a phone, you have to take some additional steps. For more info, see Register your Windows Phone device for development.
  • This post assumes you’re using Microsoft Visual Studio Express 2013 for Windows.

Description:

First of all, Open Microsoft Visual Studio Express 2013 for Windows and then create new project type Blank App(Ex:FaceBookWp8.1)


1.1 Installation of Facebook SDK:
Install the Facebook nuget package into the solution by starting the Package Manager PowerShell by following:
Tools->Library Package Manager->Package Manager console
Once the powershell command prompt is running, type the following command
Install-Package Facebook, 
This will add Facebook SDK in the current project like below.

1.2 Linking App with facebook:
First of all, you need to create Facebook Application on website. Here is the link to do so https://developers.facebook.com/apps Click at "Add New App" button
Enter the Display Name, namespace (Optional) and then click 'Create App ID'.
Now go to Settings ,there click on add platform
Please note above App Id,and You must select Windows App as a platform,because in this sample we are trying to connect windowsphone 8.1 store apps.
And now the most important step is we need to fill Windows Store ID.
There are a couple of ways to get the value to be put in that field, one of them in this sample i am going to take help of WebAuthenticationBroker class like this
Uri _callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();

In my case the above statement return following URI,you may check above code by downloading the sample and observe in 'FaceBookHelper.cs' class from 'Helpers' folder in a project
We proceed to copy that Uri, on page Facebook App 'facebookwptest' a new platform and select Windows App there two fields appear, since this app are creating the Windows Phone 8.1 and then we place the Uri Windows Store ID. If I were a Silverlight App Windows Phone 8.1 we should use another field and a different Uri.
The Uri must place there Guid copying everything from "s-" without inclkuir rl "/" end being something like:
Note: As we are creating a windowsphone store app ignore the field talking about Windows Phone and we look only at the Windows Store ID.

1.3 Work with Facebook Login Page:

Before going to login any social networks,oAuth is the common authentication method nowadays for Apps and Websites,In this article I am interested to use WebAuthenticationBroker.

Note: Unlike the Windows WebAuthenticationBroker, the Phone version does not use the AuthenticateAsync method. It uses AuthenticateAndContinue instead. This is related to the lifecycle on phone, as it is more likely that an WINPRT app is suspended than on Windows (at least that’s the official reason).

But we are able to get it working, no worries. First, we need the so called ContinuationManager. This class brings the user back to the app where the fun begun.So create a folder name is 'Helpers' and add following class.


  1. namespace FaceBookWp8._1.Helpers  
  2. {  
  3.     class ContinuationManager  
  4.     {  
  5.         public void ContinueWith(IActivatedEventArgs args)  
  6.         {  
  7.             var rootFrame = Window.Current.Content as Frame;  
  8.             if (rootFrame == null)  
  9.                 return;  
  10.   
  11.             switch (args.Kind)  
  12.             {  
  13.                 case ActivationKind.PickFileContinuation:  
  14.                     break;  
  15.                 case ActivationKind.PickFolderContinuation:  
  16.                     break;  
  17.                 case ActivationKind.PickSaveFileContinuation:  
  18.                     break;  
  19.                 case ActivationKind.WebAuthenticationBrokerContinuation:  
  20.                     var continuator = rootFrame.Content as IWebAuthenticationBrokerContinuable;  
  21.                     if (continuator != null)  
  22.                         continuator.ContinueWithWebAuthenticationBroker((WebAuthenticationBrokerContinuationEventArgs)args);  
  23.                     break;  
  24.                 default:  
  25.                     break;  
  26.             }  
  27.         }  
  28.     }  
  29.     interface IWebAuthenticationBrokerContinuable  
  30.     {  
  31.         void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args);  
  32.     }  
  33. }  



Here the only thing you need to do is to add your app’s Namespace into it(Here in my case namespace is FaceBookWp8._1.Helpers).

The next step we need to do: some modifications at the App.xaml.cs file.

  1. protected async override void OnActivated(IActivatedEventArgs args)  
  2.         {  
  3.             CreateRootFrame();  
  4.   
  5.             if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)  
  6.             {  
  7.                 try  
  8.                 {  
  9.                     await SuspensionManager.RestoreAsync();  
  10.                 }  
  11.                 catch { }  
  12.             }  
  13.   
  14.             if (args is IContinuationActivatedEventArgs)  
  15.                 _continuator.ContinueWith(args);  
  16.   
  17.             Window.Current.Activate();  
  18.         }  

Add a CreateRootFrame() method with some little changes to the default behavior.

  1. private void CreateRootFrame()  
  2.        {  
  3.            Frame rootFrame = Window.Current.Content as Frame;  
  4.            if (rootFrame == null)  
  5.            {  
  6.                rootFrame = new Frame();  
  7.                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");  
  8.                Window.Current.Content = rootFrame;  
  9.            }  
  10.        }  

First, we check the SuspensionManager and let him restore a saved state – if there is one. If you do not have a Folder  "Common" with the SuspensionManager, just add a new Basic page. This will generate the Common folder with the SuspenstionManager class for you.However in this sample i added SuspensionManager class in 'Helpers" folder.

After that, we are checking if the activation is a Continuation. We need this check there, otherwise the app will not be able to receive the Tokens after returning from the WebAuthenticationBroker. 
Note: declare the ContinuationManager globally in App.xaml.cs with this to avoid multiple instances (which will crash the app for sure).

  1. ContinuationManager _continuator = new ContinuationManager();  


Of the suspension system is responsible, the event will fire OnSuspending found in the App case: App.xaml.cs , which at the moment looks like this (no need to do anything).


  1. private async void OnSuspending(object sender, SuspendingEventArgs e)  
  2.         {  
  3.             var deferral = e.SuspendingOperation.GetDeferral();  
  4.             await SuspensionManager.SaveAsync();  
  5.             deferral.Complete();   
  6.         }  



Add following class in 'Helpers' folder.Which is useful to login facebook with help of WebAuthenticationBroker.


  1. namespace FaceBookWp8._1.Helpers  
  2. {  
  3.     public class FaceBookHelper  
  4.     {  
  5.         FacebookClient _fb = new FacebookClient();  
  6.         readonly Uri _callbackUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();  
  7.         readonly Uri _loginUrl;   
  8.         private const string FacebookAppId = "xxxxxxxxxxxxxxx";//Enter your FaceBook App ID here  
  9.         private const string FacebookPermissions = "user_about_me,read_stream,publish_stream";  
  10.         public string AccessToken  
  11.         {  
  12.             get { return _fb.AccessToken; }  
  13.         }  
  14.   
  15.         public FaceBookHelper()  
  16.         {  
  17.             _loginUrl = _fb.GetLoginUrl(new  
  18.                     {  
  19.                         client_id = FacebookAppId,  
  20.                         redirect_uri = _callbackUri.AbsoluteUri,  
  21.                         scope = FacebookPermissions,  
  22.                         display = "popup",  
  23.                         response_type = "token"  
  24.                     });  
  25.             Debug.WriteLine(_callbackUri);//This is useful for fill Windows Store ID in Facebook WebSite  
  26.         }  
  27.         private void ValidateAndProccessResult(WebAuthenticationResult result)  
  28.         {  
  29.             if (result.ResponseStatus == WebAuthenticationStatus.Success)  
  30.             {  
  31.                 var responseUri = new Uri(result.ResponseData.ToString());  
  32.                 var facebookOAuthResult = _fb.ParseOAuthCallbackUrl(responseUri);  
  33.   
  34.                 if (string.IsNullOrWhiteSpace(facebookOAuthResult.Error))  
  35.                     _fb.AccessToken = facebookOAuthResult.AccessToken;  
  36.                 else  
  37.                 {//error de acceso denegado por cancelaciĆ³n en pĆ”gina  
  38.                 }  
  39.             }  
  40.             else if (result.ResponseStatus == WebAuthenticationStatus.ErrorHttp)  
  41.             {// error de http  
  42.             }  
  43.             else  
  44.             {  
  45.                 _fb.AccessToken = null;//Keep null when user signout from facebook  
  46.             }  
  47.         }  
  48.         public void LoginAndContinue()  
  49.         {  
  50.             WebAuthenticationBroker.AuthenticateAndContinue(_loginUrl);  
  51.         }  
  52.         public void ContinueAuthentication(WebAuthenticationBrokerContinuationEventArgs args)  
  53.         {  
  54.             ValidateAndProccessResult(args.WebAuthenticationResult);  
  55.         }  
  56.     }  
  57. }  

Note:Please enter your facebook App ID in above code.otherwise you will get error like below.

Now our project hierarchy will be like this.


 Wow! Now we are done almost,Let's make following UI in MainPage.xaml page to use above helpers.


  1.    <StackPanel>  
  2.             <!--Title-->  
  3.             <TextBlock Text="FaceBook Integration in WP8.1:" FontSize="28" Foreground="Gray"/>  
  4.             <!--Buttons for Login & Logout-->  
  5.             <Button Name="BtnLogin" Content="FaceBook Login" HorizontalAlignment="Stretch" Background="#FF00A9CF" Click="BtnFaceBookLogin_Click"/>  
  6.             <Button Visibility="Collapsed" Name="BtnLogout" Content="FaceBook Logout" HorizontalAlignment="Stretch" Background="#FF00A9CF" Click="BtnFaceBookLogout_Click"/>  
  7.               
  8.             <StackPanel Visibility="Collapsed" Name="StckPnlProfile_Layout">  
  9.                 <!--Display facebook profile info-->  
  10.                 <TextBlock Text="User Profile :" FontSize="30" TextWrapping="Wrap"  Foreground="White"/>  
  11.                 <Image Stretch="None" x:Name="picProfile"  HorizontalAlignment="Left" />  
  12.                 <TextBlock FontSize="20" Name="TxtUserProfile" TextWrapping="Wrap"  Foreground="White"/>  
  13.                 <!--Post wall-->  
  14.                 <TextBox Name="TxtStatusMsg" MinHeight="150" TextWrapping="Wrap" Header="Status Message:" FontSize="18" Foreground="Black"/>  
  15.                 <Button Content="Post Status on FaceBook" HorizontalAlignment="Stretch" Background="#FF00A9CF" Click="BtnFaceBookPost_Click"/>  
  16.             </StackPanel>  
  17.               
  18.         </StackPanel>  



Here in above xaml code ,there are four sections:
1)For displaying sample title.
2)Buttons for Login and Logout.
3)UI for displaying user profile info ,after successfully logon to facebook.
4)Post message to wall.

In MainPage.cs file , create following two global object for 'FaceBookHelper.cs' class and FacebookClient.

  1. FaceBookHelper ObjFBHelper = new FaceBookHelper(); 
  2. FacebookClient fbclient = new FacebookClient(); 

Ok,Let's write code for facebook login on BtnFaceBookLogin_Click Event:

  1. private void BtnFaceBookLogin_Click(object sender, RoutedEventArgs e)  
  2.        {  
  3.            ObjFBHelper.LoginAndContinue();  
  4.        }  
When clicking on Login button from UI,WebAuthenticationBroker will get facebook login url from the FaceBookHelper constructor and screen will be appeared like below.
Entered facebook username and password will be processed for authentication,and then will be ask for your permissions.Press ok for successfully logon to facebook page.
After successfully logon to facebook page,Add following method for fetching user profile data in MainPage.cs file.


  1. public async void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args)  
  2.         {  
  3.             ObjFBHelper.ContinueAuthentication(args);  
  4.             if (ObjFBHelper.AccessToken != null)  
  5.             {  
  6.                 fbclient = new Facebook.FacebookClient(ObjFBHelper.AccessToken);  
  7.   
  8.                 //Fetch facebook UserProfile:  
  9.                 dynamic result = await fbclient.GetTaskAsync("me");  
  10.                 string id = result.id;  
  11.                 string email = result.email;  
  12.                 string FBName = result.name;  
  13.   
  14.                 //Format UserProfile:  
  15.                 GetUserProfilePicture(id);  
  16.                 TxtUserProfile.Text = FBName;  
  17.                 StckPnlProfile_Layout.Visibility = Visibility.Visible;  
  18.                 BtnLogin.Visibility = Visibility.Collapsed;  
  19.                 BtnLogout.Visibility = Visibility.Visible;  
  20.             }  
  21.             else  
  22.             {  
  23.                 StckPnlProfile_Layout.Visibility = Visibility.Collapsed;  
  24.             }  
  25.               
  26.         }  


To get user profile image,add following method:

  1. private void GetUserProfilePicture(string UserID)  
  2.         {  
  3.             string profilePictureUrl = string.Format("https://graph.facebook.com/{0}/picture?type={1}&access_token={2}", UserID, "square", ObjFBHelper.AccessToken);  
  4.             picProfile.Source = new BitmapImage(new Uri(profilePictureUrl));  
  5.         }  

1.4 Post status message on FaceBook Wall:

When click on Post Status button,add following code in MainPage.cs file,

  1. private async void BtnFaceBookPost_Click(object sender, RoutedEventArgs e)  
  2.         {  
  3.             var postParams = new  
  4.             {  
  5.                 name = "Facebook Post Testing from App.",  
  6.                 caption = "WindowsPhone 8.1 FaceBook Integration.",  
  7.                 link = "http://bsubramanyamraju.blogspot.in",  
  8.                 description=TxtStatusMsg.Text,  
  9.                 picture = "http://facebooksdk.net/assets/img/logo75x75.png"  
  10.             };  
  11.             try  
  12.             {  
  13.                 dynamic fbPostTaskResult = await fbclient.PostTaskAsync("/me/feed", postParams);  
  14.                 var responseresult = (IDictionary<stringobject>)fbPostTaskResult;  
  15.                 MessageDialog SuccessMsg = new MessageDialog("Message posted sucessfully on facebook wall");  
  16.                 await SuccessMsg.ShowAsync();  
  17.             }  
  18.             catch (Exception ex)  
  19.             {  
  20.                 //MessageDialog ErrMsg = new MessageDialog("Error Ocuured!");  
  21.                   
  22.             }  
  23.         }  

After posting status,we will be found status message on your facebook timeline like below,

1.5 Logout from Facebook Page:

When click on Logout button,add following code in MainPage.cs file,


  1. private async void BtnFaceBookLogout_Click(object sender, RoutedEventArgs e)  
  2.         {  
  3.             _logoutUrl = fbclient.GetLogoutUrl(new  
  4.             {  
  5.                 next = "https://www.facebook.com/connect/login_success.html",  
  6.                 access_token = ObjFBHelper.AccessToken  
  7.             });  
  8.             WebAuthenticationBroker.AuthenticateAndContinue(_logoutUrl);  
  9.             BtnLogin.Visibility = Visibility.Visible;  
  10.             BtnLogout.Visibility = Visibility.Collapsed;   
  11.         }  

FacebookIntegrationWP8.1

Summary:
From this article we have learned "Facebook Integration in windowsphone 8.1 application".Hope i wrote this post with my best level,When writing this article, i had taken lot of hard works and making nice presentation to understand the article at beginners level.


FeedBack Note:
Please share your thoughts,what you think about this post,Is this post really helpful for you?I always welcome if you drop comments on this post and it would be impressive.

Follow me always at  
Have a nice day by  :)



79 comments:

  1. Nice Tutorial about Facebook Integration in windows phone 8.1.... Its very useful for us.. Thanks Subbu

    ReplyDelete
  2. This was really helpful! :) I've been struggling to integrate windows login on WP 8.1!
    And right now my page is stuck at "login success". Can you help me with that?

    ReplyDelete
    Replies
    1. Check once following things:
      1)Your facebook app is must be approved.
      2)Make sure to fill Windows Store ID from Step 1.2
      3)Make sure to enter your correct APP ID in FaceBookHelper.cs file

      Delete
    2. I did all that. When I put anything other than "http://www.facebook.com/connect/login_success.html" in the redirect uri, I get invalid url. What can I do to move back to my app?

      Delete
    3. Hey! I didn't do that Windows store step. Thats where I was going wrong! Thank you so much ! :) This helped me a lot!!!

      Delete
  3. Hey! I found something else. When I login after authorising the app again it says "You have authorized the app already". Is there any way for a already authorized user to not see that page?

    ReplyDelete
    Replies
    1. Thanks for your notice and you are right! and i need to work on it..You may also share with me,if you are solved that bug.So that it will be useful for future visitors :)

      Delete
    2. I'm stuck in the same issue. Can you please share the solution for this? Thanks.

      Delete
    3. This might help - http://stackoverflow.com/questions/32078145/how-to-prevent-you-have-already-authorized-this-app-message-on-facebook-connec/32086220#32086220

      Delete
    4. Have you been able to solve this issue? I still get the "You have authorized the app already" message.

      Delete
  4. Hey how did u get that windows store id ..? Please help me out

    ReplyDelete
  5. Hi

    I have an issue with login. After login I get a message "Success" and also a warning message "SECURITY WARNING: Please treat the URL above as you would your password and do not share it with anyone." I don't receive the access token too. Can you suggest how to solve this issue.

    ReplyDelete
  6. Hi,

    Thank you for the great tutorial, it's been an amazing help. I have one question, when logging out of a Facebook account using the demo, a generic Facebook "Success" page appears. For a production app it would be necessary to have a cleaner log-out, is it possible to avoid that "Success" page?

    Thank you

    ReplyDelete
  7. Hi,

    I am doing the windows phone 8.1 silver light app . For this I integrated the facebook . For log in process I used the log in with app method , For testing i created one sample in vs and at the developers.facebook.com , and I have placed the product id from the wmmanifest.xml which is present in place holder , and I am able to login with the sample .
    Now for live app I got my app id from the store , can you please tell me where to replace this app id , I am confused where to replace this app id . I tried to put this in dev.fb.com and wm.manifest.xml and in extensions tag , by doing this
    I am getting error message from facebook saying that calling app id not matched calling app id .

    Any help..


    Thanks...

    ReplyDelete
    Replies
    1. You should follow my previous articleFacebook login support with windowsphone 8 silverlight apps. .And in this post i mentioned in step 2.

      Delete
    2. yes I followed that manual only but After updating the product id present in the placeholder I am getting error message saying that wmmanifest.xml signature is invalid try with new signature.. How to over come this...

      Delete
    3. there is no need to change the product id in the wmmanifest,xml with the store app id am i correct

      Delete
    4. See in previous article in step 3

      Delete
  8. Check this two things
    1)updating the store product id in the facebook website placeholder
    2)Change app id in manifest file ,
    under Extensions
    If you miss any of above steps,you will be fail

    ReplyDelete
    Replies
    1. I have replaced the store app id in those two places told by you , after executing it I am getting error messgae from facebook saying that calling appid does not match the calling app id.

      Is it not possible to test the app without publishing?

      Delete
    2. Be aware that the product ID used during development is a randomly assigned placeholder. After your app has been certified, it has a different product ID.In this case, submit your app first to get a product ID assigned, but select the Manual publish option to ensure that you don’t release an app that is not set up correctly on the Facebook Developers site.Once you have your final product ID, make sure you update your WMAppManifest.xml under Extensions

      Delete
    3. yes I remembered those two points , please give me clarity that is it possible to test the app without publishing or not after changing the app id in dev.fb.com and in wmmanifest.xml under extensions.

      Delete
    4. Yes you can test without publishing,but make sure remembering above two steps.

      Delete
    5. does this work after changing the store id in those two places and publishing to the store also .

      Delete
    6. thank you so much for your information.. It is very nice talking to you..............

      Delete
  9. testing in the sense facebook authentication checking...

    ReplyDelete
  10. After successfull log in to facebook , this function ContinueWithWebAuthenticationBroker was not getting called.
    Can you please help on that

    ReplyDelete
    Replies
    1. Same problem here, can you please help?

      Delete
    2. Try to check your class interface, do not forget to add "IWebAuthenticationBrokerContinuable"

      Example
      public sealed partial class MainPage : Page, IWebAuthenticationBrokerContinuable
      {
      .....

      Delete
  11. can we have any google account integration in windows phone 8.1 ?

    ReplyDelete
  12. this is a good tutorial. I am still trying to get the app id but once I get over that issue I should be able to integrate it into my windows phone app

    ReplyDelete
  13. Login page does not come. I get this error while debugging
    The remote procedure call failed. (Exception from HRESULT: 0x800706BE)
    at Windows.Security.Authentication.Web.WebAuthenticationBroker.AuthenticateAndContinue(Uri requestUri)

    ReplyDelete
  14. I have replaced the store app id in those two places told by you , after executing it I am getting error messgae from facebook saying that calling appid does not match the calling app id.
    facebook

    ReplyDelete
  15. this is a good tutorial. I am still trying to get the app id but once I get over that issue I should be able to integrate it into my windows phone app facebook

    ReplyDelete
  16. this is a good tutorial. I am still trying to get the app id but once I get over that issue I should be able to integrate it into my windows phone app .
    facebook

    ReplyDelete
  17. Thanks very much for this great article;this is the stuff that keeps me going through out these day.
    facebook

    ReplyDelete
  18. hi, thanks for the guide! but i'm stuck on logging in with facebook.. that say me that given url is not permitted byapplication configuration ecc. , i've set my AppID in facebookHelper class... Can you help me?
    Thanks!!!

    ReplyDelete
    Replies
    1. Be sure to set the correct Store Id on Facebook page.
      in your code run the WebAuthenticationBroker.GetCurrentApplicationCallbackUri() and see what is the code, because you probably have something different in the app, than registered on facebook

      Delete
  19. Hi,

    This tutorial work for me, but I have 2 questions:

    1. I want to automate the login. I don't want to show the login button, but instead just show the login page. When I do it on Page_Loaded event (call WebAuthenticationBroker.AuthenticateAndContinue(LoginUrl);) I get the following error:
    The remote procedure call failed. (Exception from HRESULT: 0x800706BE)

    It works fine when I press the button.


    2. This works great when I run this for the first time, but later when I log in it says that I have already accepted this app. I should have got AccessToken in some other fashion then?

    ReplyDelete
  20. 1.What is use of SuspensionManager.cs class?
    2.where is in method of SuspensionManager.cs?

    ReplyDelete
  21. 1.What is use of SuspensionManager.cs class?
    2.where is in method of SuspensionManager.cs?

    ReplyDelete
  22. Hi Subbu.I am doing one application for Professional.So my requierement is i need to retrieve all installed apps list in my Application.Please help me to do this.is there any API?

    ReplyDelete
  23. Hi Subramanyam Raju,

    How can i get friend list and can u also give me all supported request and response to interact with data of facebook.

    Regards,
    Manish Makwana

    ReplyDelete
  24. 1.What is use of SuspensionManager.cs class?
    2.where is in method of SuspensionManager.cs?

    ReplyDelete
    Replies
    1. SuspensionManager is a class which is helpful for navigation purpose and It saves and restores the navigation state of the Frame. If you are creating Blank page we need to add this class for making navigation history.

      Ex: Suppose if i am navigating one page1 to page 2. And pressing on back button it will redirect to page1

      Note: Please googling about SuspensionManager class, you will get lots of info from MSDN

      Delete
  25. How about integrating twitter for wp8.1? I want to add a status through my app to twitter for sharing purposes, is that workable?

    ReplyDelete
  26. I get invalid url. ...please help

    ReplyDelete
  27. got it...but please tell me how to get the gender of the user

    ReplyDelete
  28. Hi,

    protected async override void OnActivated(IActivatedEventArgs args)
    {
    CreateRootFrame();

    if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
    {
    try
    {
    await SuspensionManager.RestoreAsync();
    }
    catch { }
    }

    if (args is IContinuationActivatedEventArgs)
    _continuator.ContinueWith(args);

    Window.Current.Activate();
    }
    I have got a successfull response but don't know while callling this line "_continuator.ContinueWith(args);" we are getting null response. so could you tell us what mistaken we have done ?

    ReplyDelete
  29. Hello,

    How to integrate Instagram api in windows phone 8.1 application
    Please help me out for that

    Thank You

    ReplyDelete
  30. Does anybody try the logout method above? I get UserCancel status response in OnActivation event

    ReplyDelete
    Replies
    1. Yes, I have also try this, but it doesn't work. Can someone help us?

      Delete
    2. I've actually changed to "winsdkfb" supported by microsoft as it seems to be use in Win 10.

      The problem with logout however still persisted, but it seems that is because of the cookies stored in application's browser.

      After quick search I've found how to delete cookies:

      Windows.Web.Http.Filters.HttpBaseProtocolFilter myFilter = new Windows.Web.Http.Filters.HttpBaseProtocolFilter();
      var cookieManager = myFilter.CookieManager;
      HttpCookieCollection myCookieJar = cookieManager.GetCookies(new Uri("https://facebook.com"));
      foreach (HttpCookie cookie in myCookieJar)
      {
      cookieManager.DeleteCookie(cookie);
      }

      Delete
  31. that was a nice tutorial sir.

    Can you please tell how to get the user's country and cover photo

    Thank you sir

    ReplyDelete
  32. can you upload images we use in this application?

    ReplyDelete
  33. read_stream and publish_stream are deprecated now

    ReplyDelete
  34. I cant use "Post status message on FaceBook Wall" function. I did write something on the textbox but when i clicked on the Post status button there was nothing happen. The other functions Login, Logout are useful, only this function cant be used. Could you plz tell me how to make it work?
    Thank you sir

    ReplyDelete
  35. Nice Tutorial about Facebook Integration in windows phone 8.1.... Its very useful for us.. Thanks Subbu. But I have 2 issues please help me!
    First: Layout for Success Page when logout. I want it return a page log in with empty account name, password textbox
    Second: Why I post status in facebook,but my friend can't see it ?

    ReplyDelete
  36. Do you have any linkedin integration into windows phone 8.1 article?

    ReplyDelete
  37. Install-package facebook giving me error

    Install-Package : Unable to find package 'Facebook'.

    ReplyDelete
  38. I am getting an error in the emulator when I click on the login buton. the erorr is"Given URL is not allowed by the application configuration: One or more of the given URLs is not allowed in the app settings. it must match the website URL or Canvas URL, or the domain must be a subdomain of one of the App''s domains.

    ReplyDelete
  39. I am getting an error in the emulator when I click on the login buton. the erorr is"Given URL is not allowed by the application configuration: One or more of the given URLs is not allowed in the app settings. it must match the website URL or Canvas URL, or the domain must be a subdomain of one of the App''s domains.

    ReplyDelete
  40. I am getting this error
    "You are using a display type of 'popup' in a large browser window or tab. For a better user experience, show this dialog with our JavaScript SDK without specifying an explicit display type. The SDK will choose the best display type for each environment. Alternatively, set height and width on your window.open() call to properly size this dialog if you have special requirements precluding you from using the SDK. This message is only visible to developers of your application."how to solve my problem.please help me.

    ReplyDelete
  41. public void ContinueWith(IActivatedEventArgs args)
    {
    var rootFrame = Window.Current.Content as Frame;


    if (rootFrame == null)
    return;

    switch (args.Kind)
    {
    case ActivationKind.PickFileContinuation:
    break;
    case ActivationKind.PickFolderContinuation:
    break;
    case ActivationKind.PickSaveFileContinuation:
    break;
    case ActivationKind.WebAuthenticationBrokerContinuation:
    var continuator = rootFrame.Content as IWebAuthenticationBrokerContinuable;
    if (continuator != null)
    continuator.ContinueWithWebAuthenticationBroker((WebAuthenticationBrokerContinuationEventArgs)args);
    break;
    default:
    break;
    }

    in the above code, continuator getting null.then below method not calling
    public async void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args)
    {
    ObjFBHelper.ContinueAuthentication(args);
    if (ObjFBHelper.AccessToken != null)
    {
    fbclient = new Facebook.FacebookClient(ObjFBHelper.AccessToken);

    //Fetch facebook UserProfile:
    dynamic result = await fbclient.GetTaskAsync("me");
    string id = result.id;
    string email = result.email;
    string FBName = result.name;

    //Format UserProfile:
    GetUserProfilePicture(id);
    TxtUserProfile.Text = FBName;
    StckPnlProfile_Layout.Visibility = Visibility.Visible;
    BtnLogin.Visibility = Visibility.Collapsed;
    BtnLogout.Visibility = Visibility.Visible;
    }
    else
    {
    StckPnlProfile_Layout.Visibility = Visibility.Collapsed;
    }
    Actually what happend is whenever i click login button it goes to login page and successfully login but userdata not found .i.e., above method not calling. I want to get user data.how to get user data .please help me.

    ReplyDelete
    Replies
    1. did you find why Continuator is null? i have the same problem

      Delete
  42. This comment has been removed by the author.

    ReplyDelete
  43. var continuator = rootFrame.Content as IWebAuthenticationBrokerContinuable;
    if (continuator != null)
    {
    Debug.WriteLine("ContinuationManager::ContinueWith continuator OK > ContinueWithWebAuthenticationBroker");
    continuator.ContinueWithWebAuthenticationBroker(args as WebAuthenticationBrokerContinuationEventArgs);
    }
    else
    {
    Debug.WriteLine("ContinuationManager::ContinueWith continuator NULL");
    }

    continuator value is NULL. so my IWebAuthenticationBrokerContinuable is not call.
    How i can fix that?

    ReplyDelete
  44. I have the same error of continuator getting a null value.I do not seem to understand why.
    Please help.

    ReplyDelete
  45. Hi I had the same error but I solved this using the CoreApplicationView class which is used in this example http://windowsapptutorials.com/windows-phone/media/using-fileopenpicker-in-windows-phone-8-1-to-choose-picture-from-picture-gallery/. I used the viewActivated event to handle the WebAuthenticationBrokerContinuationEventArgs and it works for me. However I don't know if this is the ideal solution to handle the suspension state of winrt apps.

    ReplyDelete
  46. Face the Error of An exception of type 'System.NotImplementedException' occurred in AllEvents_fb.exe but was not handled in user code

    Help me out... how to solve this???

    ReplyDelete
  47. Hi, very god tutorial, but a have this error: WebAuthenticationBroker name does not exist in the context atual

    ReplyDelete
  48. Thanks a lot for sharing this list with us. I was searching it for a long time.
    magento development company | web design and development company

    ReplyDelete
  49. Hello sir when I am going to click on Btn_Post Button message is not posted
    so plz give me solution

    ReplyDelete
  50. i always get this error - can't load URL...
    i don't know how to resolve it
    please help me..

    ReplyDelete
  51. class ContinuationManager
    {
    public void ContinueWith(IActivatedEventArgs args)
    {
    var rootFrame = Window.Current.Content as Frame;
    if (rootFrame == null)
    return;

    switch (args.Kind)
    {
    case ActivationKind.PickFileContinuation:
    break;
    case ActivationKind.PickFolderContinuation:
    break;
    case ActivationKind.PickSaveFileContinuation:
    break;
    case ActivationKind.WebAuthenticationBrokerContinuation:
    var continuator = rootFrame.Content as IWebAuthenticationBrokerContinuable;
    if (continuator != null) // It returns null value
    continuator.ContinueWithWebAuthenticationBroker((WebAuthenticationBrokerContinuationEventArgs)args);
    break;
    default:
    break;
    }
    }
    }
    interface IWebAuthenticationBrokerContinuable
    {
    void ContinueWithWebAuthenticationBroker(WebAuthenticationBrokerContinuationEventArgs args);
    }



    ------------- In 'ContinuationManager' class:

    var continuator = rootFrame.Content as IWebAuthenticationBrokerContinuable;
    if (continuator != null)
    // 'continuator' varaible returns null value, that's why application terminate .Any solution ?

    ReplyDelete
  52. Thanks for sharing ..
    How can we get friends online status ?

    ReplyDelete
  53. I am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. I enjoyed every little bit part of it and I will be waiting for the new updates.
    Facebook app development company

    ReplyDelete

Search Engine Submission - AddMe