Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize sample code #14

Merged
merged 2 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@

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/).

1. [Parse](parse)
1. [Heroku](heroku)
1. [Hubot](hubot)
1. [Hubot](hubot)
2 changes: 1 addition & 1 deletion heroku/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This is a sample client for [Facebook's Graph API Webhooks](https://developers.f

### Heroku
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)
1. Test your deployment with `curl https://<your-subdomain>.herokuapp.com` - you should see "It works!".
1. Test your deployment with `curl https://<your-subdomain>.herokuapp.com` - you should see a list of received webhooks.
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).

### Facebook
Expand Down
24 changes: 10 additions & 14 deletions heroku/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ app.listen(app.get('port'));
app.use(xhub({ algorithm: 'sha1', secret: process.env.APP_SECRET }));
app.use(bodyParser.json());

var received_updates = [];

app.get('/', function(req, res) {
console.log(req);
res.send('It works!');
res.send('<pre>' + JSON.stringify(received_updates, null, 2) + '</pre>');
});

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

app.post('/facebook', function(req, res) {
console.log('Facebook request body:');
console.log('Facebook request body:', req.body);

if (req.isXHub) {
console.log('request header X-Hub-Signature found, validating');
if (req.isXHubValid()) {
console.log('request header X-Hub-Signature validated');
res.send('Verified!\n');
}
}
else {
if (!req.isXHubValid()) {
console.log('Warning - request header X-Hub-Signature not present or invalid');
res.send('Failed to verify!\n');
// recommend sending 401 status in production for non-validated signatures
// res.sendStatus(401);
res.sendStatus(401);
return;
}
console.log(req.body);

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

app.post('/instagram', function(req, res) {
console.log('Instagram request body:');
console.log(req.body);
// Process the Instagram updates here
received_updates.unshift(req.body);
res.sendStatus(200);
});

Expand Down
10 changes: 0 additions & 10 deletions parse/.parse.local

This file was deleted.

7 changes: 0 additions & 7 deletions parse/.parse.project

This file was deleted.

24 changes: 0 additions & 24 deletions parse/README.md

This file was deleted.

44 changes: 0 additions & 44 deletions parse/cloud/main.js

This file was deleted.