Now Direct Facebook Login Support available With Windows Phone 8 C#

Now Direct Facebook Login Support available With Windows Phone 8 C#

Advertisemen

Introduction

Facebook Login provides a fast and secure sign up experience across web, iOS, and Android apps. However, Microsoft is adding official support for Facebook Login in Windows 8 and Windows Phone 8 appsin partnership with Facebook. Facebook Login for Windows 8 is ready to use in production apps, while Windows Phone 8 support is being launched in beta.
So that as a developer part,Not only does Facebook Login reduce the amount of code you need to write for your app to log in to Facebook, it also improves the user experience by not requiring the user to log in again if they are already logged in to the Facebook app.

Building the Sample

Important note1: Facebook Login is initially being released as part of the Facebook Beta app (version 5.2.2.1). Please read the description below carefully to get up and running.so that  If developing and testing on a Windows Phone, make sure you have the latest Facebook Beta app installed (version 5.2.2.1 or higher). 
note2: If developing and testing on an emulator, make sure that the Facebook Login Simulator project included in this sample is set to deploy and run.And  you cannot install the Facebook app from the Store on an emulator.so that please run this sample in physical device

Description


How ever ,as a windows phone developer we need to follow some few steps for facebook login support

1. Install NuGet packages

Install the latest NuGet packages for the Facebook SDK for .NET
                                     (or)
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 two commands
Install-Package Facebook
Intall Nuget





Install-Package Facebook.Client -pre
Intall Nuget

These will download the nuget packages and install the SDK into your project and add it to the references.
Facebook Reference
Note: The -pre flag is applied to the Facebook.Client NuGet package because it is still in preview mode owing to currently being in active development. Once this package is stable, you will not need the -pre flag.
Make sure the latest nuget packages for the Facebook SDK for .NET are installed. See here for more information: http://facebooksdk.net/docs/phone/tutorial/

                                                            (or)
Currently you may add  facebook dll's by Unzip to a local folder of this sample.

2.Update your app on the Facebook Developers site for APP ID


You also need to enter some information about your app in the Facebook Developers site, for example, identify your application ID in the Windows Phone Store so Facebook can ensure only your app gets access tokens granted by users to your Facebook app.
1. Go to http://developers.facebook.com and log in.
2. Click Apps in the top navigation bar.
3. Select your Facebook app in the left pane (or create a new one if you are starting from scratch).
4. Click edit settings.
5. Under select how your application integrates with Facebook, find the section for Windows App and expand it.
6. Enter exactly the same product ID you entered in your WMAppManifest.xml file, the {ProductID} portion (without dashes) of your msft-{ProductID} custom URI scheme.

Important note: See earlier note on how the product ID is different during development and after submission. This is crucial if you have not yet been assigned a product ID.
Here’s an example of how the Facebook Developers site looks when set up.

3) Configuring your app for Facebook Login

App manifest

Configure your app’s manifest file (WMAppManifest.xml) to register a custom uri scheme that is of the form msft-{ProductID}, where {ProductID} is your app’s product ID (without dashes). It should look like this:

XAML

<Extensions
      <Protocol Name="msft-4ce6ab44b7f9442482de17535b713cde" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" /> 
 </Extensions>

Important note: If you have not yet submitted your app to the Windows Phone Store, 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 to Use the final product ID rather than the randomly assigned placeholder. See here for more information about the submission process.

4) Lets start with Facebook Login

The facebook app id (this is the ID given by facebook in the developer portal for your app)      

C#
lass="preview" style="margin-top: -15px;">
privateconststring AppId = "Enter Your APP ID here";
 After 

Using the Facebook.Client package, make a call toFacebook.Client.FacebookSessionClient.LoginWithApp(). This method has different overloads, which require the following parameters:
  • The set of permissions your app is requesting
  • A custom state parameter, which is echoed back to your application upon login completion. This can be used to redirect the user back to the original page within your application that initiated login, or any other app specific logic.
So after tap on login button Intially screens appeared like this
After login with facebook beta app,you may see this error ,beacuse your app id is not match with appmanifest product id

After successfully login with facebook beta app,you may redirect to your app.and screen appeareded like

5) How to Share Status Message on faceBook


C#

private async void UpdateStatusButton_OnClick(object sender, RoutedEventArgs e) 
        { 
            var session = SessionStorage.Load(); 
            if (null == session) 
            { 
                return
            } 
 
            this.ProgressText = "Updating status..."
            this.ProgressIsVisible = true
 
            this.UpdateStatusButton.IsEnabled = false
 
            try 
            { 
                var fb = new FacebookClient(session.AccessToken); 
 
                await fb.PostTaskAsync(string.Format("me/feed?message={0}"this.UpdateStatusBox.Text), null); 
 
                await this.GetUserStatus(fb); 
 
                this.UpdateStatusBox.Text = string.Empty; 
            } 
            catch (FacebookOAuthException exception) 
            { 
                MessageBox.Show("Error fetching user data: " + exception.Message); 
            } 
 
            this.ProgressText = string.Empty; 
            this.ProgressIsVisible = false
            this.UpdateStatusButton.IsEnabled = true
        }

6) How to Handle  faceBook Login page launch


C#

public override Uri MapUri(Uri uri) 
        { 
            // if URI is a facebook login response, handle the deep link (once per invocation) 
            if (AppAuthenticationHelper.IsFacebookLoginResponse(uri)) 
            { 
                FacebookSession session = new FacebookSession(); 
 
                try 
                { 
                    session.ParseQueryString(HttpUtility.UrlDecode(uri.ToString())); 
 
                    // Handle success case 
 
                    // do something with the custom state parameter 
                    if (session.State != "custom_state_string"
                    { 
                        MessageBox.Show("Unexpected state: " + session.State); 
                    } 
                    else 
                    { 
                        // save the token and continue (token is retrieved and used when the app 
                        // is launched) 
                        SessionStorage.Save(session); 
                    } 
                } 
                catch (Facebook.FacebookOAuthException exc) 
                { 
                    if (!this.facebookLoginHandled) 
                    { 
                        // Handle error case 
                        MessageBox.Show("Not signed in: " + exc.Message); 
 
                        this.facebookLoginHandled = true
                    } 
                } 
 
                return new Uri("/MainPage.xaml", UriKind.Relative); 
            } 
 
            // by default, navigate to the requested uri 
            return uri; 
        }
References:

1)http://blogs.windows.com/windows_phone/b/wpdev/archive/2013/11/14/sign-into-windows-phone-8-apps-with-facebook-login.aspx

2)http://facebooksdk.net/docs/phone/tutorial/

3)https://developers.facebook.com/blog/post/2013/11/14/microsoft-adds-facebook-login-support-to-windows-8-and-windows-phone-8/

Related posts:
  1. WindowsPhone Store 8.1 : FaceBook Integration Sample (C#-Xaml)
  2. WindowsPhone Facebook Integration:How to post message/image to FaceBook Fan Page(C#-XAML)
  3. Latest Twitter integration in windows phone 8 c#


Have a nice day by 

Advertisemen

Disclaimer: Gambar, artikel ataupun video yang ada di web ini terkadang berasal dari berbagai sumber media lain. Hak Cipta sepenuhnya dipegang oleh sumber tersebut. Jika ada masalah terkait hal ini, Anda dapat menghubungi kami disini.

Tidak ada komentar:

Posting Komentar

© Copyright 2017 Tutorial Unity 3D