Last active
May 9, 2019 00:36
-
-
Save jcipriano/4820fe05152769cc87d4322897755707 to your computer and use it in GitHub Desktop.
Creates a Twitter webhook config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.') | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
npm install request
create-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