Computer Beacon high quality .NET libraries in open source

Two steps to use Facebook's API

There are many types of Facebook Apps, and many kinds of API, but they all come down to this basic routine:

  1. Obtain an access token
  2. Use the token to make API calls

 

The FGT library is designed around this flow. The Portable Library component contains all the classes you need to make API calls to Facebook, you can run it in .NET 4.0 Client Profile, Windows 8 App, ASP.NET server, or anywhere you like, as long as you provide a valid token to your calls. The classes in Facebook.Server namespace are expected to be used on a ASP.NET server, they help you obtain an access token if you choose to get one that way.

Obtaining an access token (a.k.a. Authorization)

Most of the API calls provided by Facebook require an access token. Each token has a few properties:

  1. Associated to a particular Facebook App
  2. Associated to a particular Facebook User
  3. Represents a set of "permissions" granted by the user to the app
  4. Has an expire time

 

From this, we can quickly derive some limitations on a token:

  1. We cannot use a token we got in App A in App B.
  2. Likewise, we cannot use a token we got from User A for querying info of User B.
  3. It is not practical to store tokens in a database

 

More about "Permissions"

To protect user's privacy, Facebook restrains the data apps are allowed to access. Without an access token, you can only query public information on Facebook. With an access token, you can query some basic information of your user, like the user's id, name etc.

There is a whole list of permissions on Facebook's documentation at https://developers.facebook.com/docs/facebook-login/permissions/ and I will not go through them all. Here are some of the most common permissions developers ask:

Remember, apps that require more permissions generally have a lower "authorization rate" - more users will turn away at the authorization dialog.

 

If you are uncertain about what kind of permissions you need, forget it for the time being, you can always add it back later. For now, we will setup new Facebook App and get FGT going.

Make a API call

Tokens can be used the same way no matter how you get one. You can get a token from an Andriod app, pass it to the server and then call Facebook's API at the server. Or you can call it in a desktop app. It does not make any difference.