Integrating with Facebook on Windows Phone 7

I recently helped a collegue with Facebook integration on Windows Phone 7. The requirement was to log in and post a link to the users stream. I quickly came across the Facebook C# SDK found on codeplex at: Unfortunately the otherwise pretty straight forward API is poorly documented, so it took me a bit of trial and error to get what I wanted. Here are the steps I took:

I grabbed the package containing both assemblies, source and last but not least samples. After unpacking I opened up the “CSWinPhone7SimpleApp.sln” solution from the Samples directory. At first the sample woulden’t build becaus of missing references. I fixed that by building the “Facebook-WP7.sln” solution found in the Source directory and referencing the resulting .dll’s. I then proceeded to launch the application in the emulator and got an error message in a small browser window.

It turns out the first thing you have to do is register you app with Facebook and get an app id. Go to, log in and click “+ Set Up New App” in the upper right corner.

With the app id pasted into the sample, the application started and I was presented with a login screen. After filling in my credentials and hitting “Login” I was presented with my personal details as entered on Facebook.

Next up was the task of posting to the event stream. The documentation page found here, shows basic usage, but it turns out the “Post Publish” example dosen’t compile on Windows Phone becaus it makes use of the dynamic keyword that isn’t available on Windows Phone. Going back to the example app it turns out that there’s a different syntax for Windows Phone:

Instead of using dynamics like so:

var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article"; = "";
parameters.picture = ""; = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.privacy = new {
	value = "ALL_FRIENDS",
dynamic result = client.Post("me/feed", parameters);

Use dictionaries like so:

    private void Post(FacebookClient _fbClient)
        var client = _fbClient;
        var parameters = new Dictionary<string, object>
                { "message", "Olav is testing Facebook C# SDK" },
                { "link", "" },
                { "picture", "" },
                { "name", "Facebook C# SDK" },
                { "caption", "" },
                { "description", "The Facebook C# SDK helps .Net developers build web, desktop, Silverlight, and Windows Phone 7 applications that integrate with Facebook." },
                { "privacy", new Dictionary<string, object>
                        { "value",  "ALL_FRIENDS" }

        client.PostAsync("me/feed", parameters);

Last but not least i had to add the “publish_stream” permission to the list of permissions stored in the _extendedPermissions field in the sample application (available permissions can be found here:

And finally here’s what it looks like on Facebook:

And thats all there is to it. Basic Facebook usage on Windows Phone 7 – nice to know for future projects.

Tags: , , , ,

6 Responses to “Integrating with Facebook on Windows Phone 7”

  1. RedDEvil Says:

    Hi.. Nice post.. very helpful,
    But I am experiencing dificulties in

    client.PostAsync(“me/feed”, parameters);
    Getting an exception here…

    Can You please provide the whole Publish stream part and are you navigating to another page for posting or ???..Can you please elaborate on Publishing..

    • Olav Rask Says:

      Since i just changed job i seem to have misplaced the sourcecode, but so far as i remember theres a Completed event on the client object. Hook up to that en have a look at what kind of error is in the argument maybe? Or if you’r not event getting that far maybe post the exception you are experiencing..

  2. Mayank Taneja Says:

    can you please post the code for accessing the friend list and stuff like that using the new sdk.
    thnx a lot

  3. Moni Says:

    Hi.. this post very helpful,
    but i am facing some problem after calling
    the client.PostAsync(“me/feed”, parameters);
    not able to see any change on “FacebookLoginBrowser” control.
    just see the success message.
    please help to resolve this

  4. Pete Stockley Says:

    After you set up a new app, which of the following options did you select as I cannot get past the log in screen on my WP7 app.
    Current options (16/11/2011) include:
    -App on FB
    -Native iOS
    -Native Android
    -Page Tab

    There is no native WP7 app option available.


  5. momo Says:

    exactly what i needed, thanks for sharing !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: