-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfacebook_message_poster.js
More file actions
30 lines (23 loc) · 994 Bytes
/
facebook_message_poster.js
File metadata and controls
30 lines (23 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var request = require('request');
function postMessage(access_token, message, response) {
// Specify the URL and query string parameters needed for the request
var url = 'https://graph.facebook.com/me/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);
});
}
exports.postMessage = postMessage;