Skip to content

Instantly share code, notes, and snippets.

@michaelfward
Created May 20, 2015 23:54
Show Gist options
  • Save michaelfward/d2d93faa4f80fbd7ebfb to your computer and use it in GitHub Desktop.
Save michaelfward/d2d93faa4f80fbd7ebfb to your computer and use it in GitHub Desktop.
Function to generate facebook access token. Requires the https library, an object named keys with app ID and client secret, and facebook-node-sdk
function generateAccessToken(callback){
var requestUrl = 'https://graph.facebook.com/oauth/access_token?client_id='+keys.facebook.appID+'&client_secret='+keys.facebook.secret+'&grant_type=client_credentials';
https.get(requestUrl, function(response){
response.on('data', function(data){
var token = data.toString('utf-8').split("access_token=");
FacebookClient.setAccessToken(token[1]);
callback();
});
}).on('error', function(error){
console.log(error);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment