Skip to content

Instantly share code, notes, and snippets.

@Philmod
Created August 12, 2013 22:38
Show Gist options
  • Save Philmod/6216000 to your computer and use it in GitHub Desktop.
Save Philmod/6216000 to your computer and use it in GitHub Desktop.
Post on a facebook page.
var request = require('request');
function postMessage(access_token, page_id, message, response) {
// Specify the URL and query string parameters needed for the request
var url = 'https://graph.facebook.com/' + page_id + '/feed';
var params = {
access_token: access_token,
message: message
};
// Send the request
request.post({url: url, qs: params}, function(err, resp, body) {
// Handle any errors that occur
if (err) return console.error("Error occured: ", err);
body = JSON.parse(body);
if (body.error) return console.error("Error returned from facebook: ", body.error);
// Generate output
var output = '<p>Message has been posted to your feed. Here is the id generated:</p>';
output += '<pre>' + JSON.stringify(body, null, '\t') + '</pre>';
// Send output as the response
response.writeHeader(200, {'Content-Type': 'text/html'});
response.end(output);
});
}
var token = 'blablabla'
, page_id = '12345'
;
postMessage(token, page_id, 'test', null);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment