Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I am trying to figure out a simple code for logging in facebook from a Windows Phone 8.1 app (C#).

As the Facebook Client from NuGet doesn't target Windows Phone 8.1, it seems I'd have to write some extra code. As I read in this facebook post, I'd need to launch an Uri to invoke the Login Dialog. That much, I managed to do :

 await Launcher.LaunchUriAsync(FacebookUri.DisplayLoginDialog);

where DisplayLoginDialog is a static string object with the required necessary data on the request (appId, productId, permissions, etc). I was redirected to the facebook app, to accept that my app requires such permissions.

And I accepted.

So what now? How do I get a response or something with the access_token? I have researched a lot for this but I wasn't able to find relevant posts.

The same facebook link from above, says at the section of Handling the Login Dialog that :

If someone successfully logs in, the URI association of your app will be automatically triggered, meaning they will be sent to your app, along with an access token:

msft-{ProductID}://authorize/?
access_token={user-access-token}&
expires_in={expiration-time-of-token}

But I am confused on how to actually use this in C#.

How do I get a response with the access token after the login suceeded or and error code and error message if it failed, like it is written in the facebook post?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
205 views
Welcome To Ask or Share your Answers For Others

1 Answer

In the Package.appxmanifest file, go to 'Declarations' Tab and add a Protocol Declaration.

In the Name Field, enter your Microsoft product id as 'msft-PRODUCT_ID' [product id without dashes].

In the App.xaml.cs file, add the following code

    protected override void OnActivated(IActivatedEventArgs args)
    {
        if (args.Kind == ActivationKind.Protocol)
        {
            ProtocolActivatedEventArgs eventArgs = args as ProtocolActivatedEventArgs;

            Uri responseUri = eventArgs.Uri;

           //Now you can use responseUri to retrieve the access token and expiration time of token

        }

        base.OnActivated(args);
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...