Creates a Twitter webhook config
| var request = require('request') | |
| // twitter authentication | |
| var twitter_oauth = { | |
| consumer_key: 'TWITTER_CONSUMER_KEY', | |
| consumer_secret: 'TWITTER_CONSUMER_SECRET', | |
| token: 'TWITTER_ACCESS_TOKEN', | |
| token_secret: 'TWITTER_ACCESS_TOKEN_SECRET' | |
| } | |
| var WEBHOOK_ID = 'your-webhook-id' | |
| // request options | |
| var request_options = { | |
| url: 'https://api.twitter.com/1.1/account_activity/webhooks/' + WEBHOOK_ID + '/subscriptions.json', | |
| oauth: twitter_oauth | |
| } | |
| // POST request to create webhook config | |
| request.post(request_options, function (error, response, body) { | |
| if (response.statusCode == 204) { | |
| console.log('Subscription added.') | |
| } else { | |
| console.log('User has not authorized your app.') | |
| } | |
| }) |
| var request = require('request') | |
| // twitter authentication | |
| var twitter_oauth = { | |
| consumer_key: 'TWITTER_CONSUMER_KEY', | |
| consumer_secret: 'TWITTER_CONSUMER_SECRET', | |
| token: 'TWITTER_ACCESS_TOKEN', | |
| token_secret: 'TWITTER_ACCESS_TOKEN_SECRET' | |
| } | |
| var WEBHOOK_URL = 'https://your-webhook-url' | |
| // request options | |
| var request_options = { | |
| url: 'https://api.twitter.com/1.1/account_activity/webhooks.json', | |
| oauth: twitter_oauth, | |
| headers: { | |
| 'Content-type': 'application/x-www-form-urlencoded' | |
| }, | |
| form: { | |
| url: WEBHOOK_URL | |
| } | |
| } | |
| // POST request to create webhook config | |
| request.post(request_options, function (error, response, body) { | |
| console.log(body) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
jcipriano commentedJun 14, 2017
•
edited
npm install requestcreate-webhook-config.js. Note returned webhook ID.add-subscription.js.More info in the docs:
https://dev.twitter.com/rest/direct-messages
https://dev.twitter.com/webhooks