Make FQL queries from the latest Windows 10 Facebook SDK

Facebook integration is often a vital component of any app that requires some sort of social network integration. That's probably why Microsoft wrote and open-sourced a new one in July, even before Windows 10 got officially released. Yeah, it's on GitHub and it's a bit different than the one we were used to back on Windows Phone 8.1 (however, it also works on Windows/Windows Phone 8.1!), but the functionalities should (mostly) match.

If you're interested in the official documentation, it's also available on GitHub. However, one thing is missing, and that is - how to make FQL queries.

Facebook Query Language queries are deprecated but they are not completely gone. Version 2.0 of the Facebook Platform API is the last version where FQL will be available, which means that all the apps that were created before or while that version was the latest one, can still keep using FQL calls until it gets completely shut down sometimes in 2016.

So, if you're porting an older app to UWP and have FQL queries, seems that you can continue to use them for a while and port your app to UWP more easily.

Getting the FBSession

FBSession is now the main star of the new Facebook SDK and represents the Facebook session. So, let's have a simple method that gets the active FBSession.

private FBSession GetFacebookSession()  
    FBSession session = FBSession.ActiveSession;

    session.SetAPIVersion(2, 0);

    session.FBAppId = this.app_id;
    session.WinAppId = this.sid;

    return session;

Notice a couple of things: first of all, I am setting the API version to 2.0 That's the last one that supports FQL, and without this, the SDK will target v2.1. Next thing are the IDs. The FBAppId represents the AppId you get from Facebook developers page when you create it. WinAppId is your Windows 10 UWP app id. If you don't know how to find those two values, check out the documentation

Making a query to FQL endpoint

I'm using a simple button to initiate login + querying and a TextBlock to show the response.

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">  
    <StackPanel HorizontalAlignment="Center">
        <Button x:Name="Login" 
                Content="Login and query" 
                Click="Login_OnClick" />
        <TextBlock x:Name="ResponseJson" 
                   FontSize="19" />

On button click, first part does the login:

FBSession sess = GetFacebookSession();  
FBResult loginResult = await sess.LoginAsync(null);  

and then if the login succeeded, a query is made and the response (in JSON format) is displayed in the TextBlock.

if (loginResult.Succeeded)  
    string path = "fql";
    string query = "SELECT name FROM user WHERE uid=me()";

    PropertySet parameters = new PropertySet
        new KeyValuePair<string, object>("q", query)

    string responseJson = await Facebook.FBClient.GetTaskAsync(path, parameters);

    this.ResponseJson.Text = responseJson;

Quite simple, right? :)

Using Facebook SDK winsdkfb to make FQL queries


Making FQL queries in the latest Facebook SDK for Windows 10 (UWP) (although it works on Windows/Windows Phone 8.1, too!) is quite easy. But don't get carried away - these calls will start failing quite soon in 2016, so once you port the app to Windows 10, start thinking about rewriting these calls to avoid having any FQL dependencies.

Are you still using FQL? Was this helpful? Share it, leave a comment! :)

About Igor Ralic

Software engineer at Microsoft. Running for Office. Passionate about making an impact with great apps & services. Stays close to coffee and away from coriander. Opinions expressed here are my own.