- The first step in creating a WPF Facebook application is to setup the application on the Facebook Developer site.
- The next step is hooking up the authentication and any required extended permissions.
- Last, you can access the API calls directly or use the BindingManager
Register a Facebook Application
When creating your application on the Facebook Web site, verify these settings depending on which application type you will create. Other settings may be left as the default value, populated as desired or modified later in development.
| Settings Tab | Setting | WPF | Silverlight |
| Basic | Developers | Add any team developers | Add any team developers |
| Connect | Connect URL | Leave blank | http://localhost:[port#] for development (change to your production URL for live app) |
| Advanced | Application Type | Desktop | Web |
| Advanced | Sandbox Mode | On for dev, Off for live app | On for dev, Off for live app |
After saving changes, be sure to note the API Key and Application Secret, which will be used by the FDT to identify your application when accessing the Facebook Platform APIs.
Authentication
WPF Applications should leverage the built-in functionality of the Desktop Session object. Construct an instance of DesktopSession passing in isWpf = true and an optional list of required extended permissions. Then call login.
Visual C#
DesktopSession session = new
DesktopSession("aff9f004793a1d32d26fe2361d5fc723", null, null, true, new
List<Enums.ExtendedPermissions>(){Enums.ExtendedPermissions.read_stream,
Enums.ExtendedPermissions.publish_stream});
session.Login();
The above code sample shows creating the Session with a set of required permissions. Using this particular constructor will result in the user getting a web page prompting for these permissions after they login. If you application does not require and extended permissions, you can use the constructor that does not include the list of permissions.
Calling Facebook
A WPF application can either access the API directly or use the BindingManager. Here is a code sample of using the API directly
Visual C#
Api api = new Api(session);
var friends = api.Friends.GetUserObjects();
If you want to use the BindingHelper classes instead of using the API, you can use the following.
Visual C#
var service = BindingManager.CreateInstance(session);
Resources
Facebook Developer Toolkit
The CodePlex home of the Facebook Developer Toolkit project. Download the toolkit, sample code, and documentation.
Facebook Developer Wiki Page
Facebook Developer wiki, the official documentation for the Facebook Platform.
Extended Permissions Documentation
Offical documentation for extended permissions.