jesse1981
4/22/2013 - 1:33 PM

A sample code to get an application access token using Thuzi / facebook-node-sdk.

A sample code to get an application access token using Thuzi / facebook-node-sdk.

var FB = require('fb');

FB.api('oauth/access_token', {
  client_id: process.env.FACEBOOK_APP_ID,
  client_secret: process.env.FACEBOOK_SECRET,
  grant_type: 'client_credentials'
}, function(res) {
  if (!res || res.error) {
    console.log('error occurred when getting access token:', res && res.error);
    return;
  }
  console.log('set application access token:', res.access_token);
  FB.setAccessToken(res.access_token);
});

function getFeed() {
  FB.api('hoge/feed', function(res) {
    if (!res || res.error) {
      callback(res ? res.error : 'unknown error');
      return;
    }
    console.log(res);
  });
}