Skip to content

Commit 21594ec

Browse files
mduppesadamgross42
authored andcommitted
Modernize sample code (fbsamples#14)
* Removed parse * cleanup heroku
1 parent 7f790ec commit 21594ec

File tree

7 files changed

+12
-102
lines changed

7 files changed

+12
-102
lines changed

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,5 @@
22

33
These are sample clients for [Facebook's Graph API Webhooks](https://developers.facebook.com/docs/graph-api/webhooks/) and [Instagram's Subscriptions API](https://www.instagram.com/developer/subscriptions/).
44

5-
1. [Parse](parse)
65
1. [Heroku](heroku)
7-
1. [Hubot](hubot)
6+
1. [Hubot](hubot)

heroku/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This is a sample client for [Facebook's Graph API Webhooks](https://developers.f
66

77
### Heroku
88
1. Deploy with this button: [![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/fbsamples/graph-api-webhooks-samples)
9-
1. Test your deployment with `curl https://<your-subdomain>.herokuapp.com` - you should see "It works!".
9+
1. Test your deployment with `curl https://<your-subdomain>.herokuapp.com` - you should see a list of received webhooks.
1010
1. For handling POST request validation (optional, but suggested), set the `APP_SECRET` [config var](https://devcenter.heroku.com/articles/config-vars) using your app secret value from your [Facebook app's settings](https://developers.facebook.com/apps).
1111

1212
### Facebook

heroku/index.js

+10-14
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ app.listen(app.get('port'));
1717
app.use(xhub({ algorithm: 'sha1', secret: process.env.APP_SECRET }));
1818
app.use(bodyParser.json());
1919

20+
var received_updates = [];
21+
2022
app.get('/', function(req, res) {
2123
console.log(req);
22-
res.send('It works!');
24+
res.send('<pre>' + JSON.stringify(received_updates, null, 2) + '</pre>');
2325
});
2426

2527
app.get(['/facebook', '/instagram'], function(req, res) {
@@ -34,31 +36,25 @@ app.get(['/facebook', '/instagram'], function(req, res) {
3436
});
3537

3638
app.post('/facebook', function(req, res) {
37-
console.log('Facebook request body:');
39+
console.log('Facebook request body:', req.body);
3840

39-
if (req.isXHub) {
40-
console.log('request header X-Hub-Signature found, validating');
41-
if (req.isXHubValid()) {
42-
console.log('request header X-Hub-Signature validated');
43-
res.send('Verified!\n');
44-
}
45-
}
46-
else {
41+
if (!req.isXHubValid()) {
4742
console.log('Warning - request header X-Hub-Signature not present or invalid');
48-
res.send('Failed to verify!\n');
49-
// recommend sending 401 status in production for non-validated signatures
50-
// res.sendStatus(401);
43+
res.sendStatus(401);
44+
return;
5145
}
52-
console.log(req.body);
5346

47+
console.log('request header X-Hub-Signature validated');
5448
// Process the Facebook updates here
49+
received_updates.unshift(req.body);
5550
res.sendStatus(200);
5651
});
5752

5853
app.post('/instagram', function(req, res) {
5954
console.log('Instagram request body:');
6055
console.log(req.body);
6156
// Process the Instagram updates here
57+
received_updates.unshift(req.body);
6258
res.sendStatus(200);
6359
});
6460

parse/.parse.local

-10
This file was deleted.

parse/.parse.project

-7
This file was deleted.

parse/README.md

-24
This file was deleted.

parse/cloud/main.js

-44
This file was deleted.

0 commit comments

Comments
 (0)