Getting an access token for your facebook server side application

14 April 2013

You’ve registered your application on facebook? You have an AppId and Secret? Well, then you’re ready to read publically available feeds.

For example I am working in incorporating public feed into
I have already done this with the php facebook library but now I’m moving to MVC4 and using the .NET Facebook library.

Obtain Access Token using AppId and Secret

I am using Facebook client 6.4.0

public void GetFeed() 
    var client = new FacebookClient();

    //obtain access token
    dynamic result = client.Get("oauth/access_token", new
        client_id = APP_ID,
        client_secret = APP_SECRET,
        grant_type = "client_credentials"

    //assign access token
    client.AccessToken = result.access_token;

    //get feed
    dynamic req = client.Get("/richardskbb/feed?limit=10");

Generate using a CRON job (tip)

I suggest you don’t inline this call during a page request since it will slow down your page rendering.
Instead, expose a route /task/run which creates some sort of cache that you can read in during a request. This route can be called using a CRON job.

If your hosting provider doesn't have CRON facility then I have used in the past as an interim solution. You get nagged on a monthly basis to renew a free account.

Accessing a user feed

The user needs to provide your application permission to access their feeds.
The user themselves needs to do this and you need to capture an access token in a redirect which itself may only be available for a limited time.

Review the Facebook API.

AuthN oAuth