locked
Facebook login RRS feed

  • Question

  • So in Windows Phone 8 you had the posibility to integrate facebook login perfectly, but in Windows Phone 8.1 it's back to basics? I don't get it.

    I am building an app for 8.1 (store & phone) and I can't seem to find any documentation on how to launch the WP facebook app for login. How do I register the protocol in the manifest file?


    If this answers your question please mark it accordingly | www.robfox.nl

    Thursday, May 1, 2014 8:34 PM

Answers

  • Hey Matt,

    Thanks for the answer. That's indeed the way to go in Windows But in Windows Phone you can launch the facebook app with a URI (single sign on) and will then perform a callback to your own app. That's different from OAuth via Web. 

    Anyway, developing for WinPhone 8.1 is pretty hard for now, since nothing is up-to-date yet. MS is a little behind there. Samples, NuGet packages (e.g. facebook), Microsoft's examples etc. are all WP8 or Silverlight 8.1 :( 

    I have got it working now, here's what I did:

    - I have added the Facebook and Facebook.Client dll manually, for NuGet fails to install the packages, since they are bound to WP 8.0.

    - I have added the following extension to my AppManifest (within application):

    <Extension Category="windows.protocol">
      <Protocol Name="msft-<productid>" />
    </Extension>

    - Then I call the Uri to launch the facebook app as documented here:

    fbconnect://authorize?
      client_id=<clientId>&
      scope=basic_info,user_photos&
      redirect_uri=msft-<productid>%3a%2f%2fauthorize
    await Launcher.LaunchUriAsync(new Uri(uri, UriKind.Absolute)); 
    

    - Then the callback will happen in the OnActivated event in App.xaml. Over here you can parse the URI and querystring that came back from the facebook app. In Windows Phone 8 you used to do that with a UriMapper.

    protected override void OnActivated(IActivatedEventArgs args)
    {
     if (args.Kind == ActivationKind.Protocol)
     {
       ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
    
       // then you can catch the uri and work with it
     }
    }
    

    So, that's basically it, but I had a hard time finding that out. But I have to admit that I haven't been developing that much lately :)






    If this answers your question please mark it accordingly | www.robfox.nl

    • Marked as answer by Roborop Friday, May 2, 2014 1:40 PM
    Friday, May 2, 2014 1:40 PM

All replies

  • I hope I'm not confused by your question, but WebAuthenticationBroker is how you login to FB:

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.authentication.web.webauthenticationbroker.aspx


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 2, 2014 1:18 PM
  • Hey Matt,

    Thanks for the answer. That's indeed the way to go in Windows But in Windows Phone you can launch the facebook app with a URI (single sign on) and will then perform a callback to your own app. That's different from OAuth via Web. 

    Anyway, developing for WinPhone 8.1 is pretty hard for now, since nothing is up-to-date yet. MS is a little behind there. Samples, NuGet packages (e.g. facebook), Microsoft's examples etc. are all WP8 or Silverlight 8.1 :( 

    I have got it working now, here's what I did:

    - I have added the Facebook and Facebook.Client dll manually, for NuGet fails to install the packages, since they are bound to WP 8.0.

    - I have added the following extension to my AppManifest (within application):

    <Extension Category="windows.protocol">
      <Protocol Name="msft-<productid>" />
    </Extension>

    - Then I call the Uri to launch the facebook app as documented here:

    fbconnect://authorize?
      client_id=<clientId>&
      scope=basic_info,user_photos&
      redirect_uri=msft-<productid>%3a%2f%2fauthorize
    await Launcher.LaunchUriAsync(new Uri(uri, UriKind.Absolute)); 
    

    - Then the callback will happen in the OnActivated event in App.xaml. Over here you can parse the URI and querystring that came back from the facebook app. In Windows Phone 8 you used to do that with a UriMapper.

    protected override void OnActivated(IActivatedEventArgs args)
    {
     if (args.Kind == ActivationKind.Protocol)
     {
       ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;
    
       // then you can catch the uri and work with it
     }
    }
    

    So, that's basically it, but I had a hard time finding that out. But I have to admit that I haven't been developing that much lately :)






    If this answers your question please mark it accordingly | www.robfox.nl

    • Marked as answer by Roborop Friday, May 2, 2014 1:40 PM
    Friday, May 2, 2014 1:40 PM
  • Documentation says that WAB is supported in both WinRT and Silverlight apps:

    Minimum supported phone

    Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Friday, May 2, 2014 2:28 PM
  • That's true and it works for every OAuth service. But Windows Phone has the ability to launch the app, in which you are already logged in, hence, don't need to enter your credentials yet again for facebook. 

    If this answers your question please mark it accordingly | www.robfox.nl

    Friday, May 2, 2014 5:43 PM
  • Where exactly did you put this within the AppManifest? I opened up the Package.appxmanifest file that was created for my project in the XML editor and just inserted it here:

    But as you can see, it doesn't like the Extension type and will not compile.

    What am I doing wrong?

    By the way, thank you so much for this little write up, it's going to be invaluable.


    • Edited by ethanku Saturday, July 5, 2014 11:45 PM
    Saturday, July 5, 2014 11:42 PM
  • Figured it out... Just go into the visual editor, head to the declarations tab and add a protocol. Then open it up in code and edit the code that was added at the bottom which will look just like his but without the Name defined.
    Sunday, July 6, 2014 6:04 AM
  • Thanks a lot Matt !
    Wednesday, July 30, 2014 11:54 PM
  • When I followed this example, I got an error back telling me that the client id did not match the client Id that was sent, but when I go down the OAuth path everything seems to work with the same client ids.  Any thoughts on what might be cuasing this?

    Also, this only seems to work for me when running under the debugger.  When I run the app on the phone, the app just crashes after launching the Facebook app or before launching the browser if using OAuth.  Any tips here to get this working properly?

    Sunday, October 5, 2014 5:48 AM
  • Here is the error message that I get (I have omitted the msft-{productid} that proceeded this message in the URI that is retruned:

    //authorize/?error=&error_code=2005&error_description=Calling+app's+ID+doesn't+match+the+ID+sent+by+the+calling+app&error_reason=Calling+app's+ID+doesn't+match+the+ID+sent+by+the+calling+app&state=

    • Proposed as answer by thehetz Sunday, October 5, 2014 7:11 AM
    • Unproposed as answer by thehetz Sunday, October 5, 2014 7:11 AM
    Sunday, October 5, 2014 6:08 AM
  • I found the answer to this issue over here: http://stackoverflow.com/questions/25190652/windows-phone-facebook-app-not-returning-access-token-after-v-8-3-1-0-update

    and now have this working as expected while running under the debugger.  But when running on the phone without the debugger attached, after the login occurs I see my splash screen again for about a minute, then the resuming message, and then the app crashes.  Any help with this would be greatly appreciated!

    Sunday, October 5, 2014 7:13 AM