Skip to content

Instantly share code, notes, and snippets.

@jcipriano
Last active November 16, 2017 19:01
Show Gist options
  • Save jcipriano/8b5098b7f3af51aaa037107f01c95b4d to your computer and use it in GitHub Desktop.
Save jcipriano/8b5098b7f3af51aaa037107f01c95b4d to your computer and use it in GitHub Desktop.
Deletes an Account Activity API webhook config.
var request = require('request')
// twitter authentication
var twitter_oauth = {
consumer_key: 'redacted',
consumer_secret: 'redacted',
token: 'redacted',
token_secret: 'redacted'
}
function getConfig() {
// request options
var request_options = {
url: 'https://api.twitter.com/1.1/account_activity/webhooks.json',
oauth: twitter_oauth
}
// GET request to retreive webhook config
request.get(request_options, function (error, response, body) {
var configs = JSON.parse(body)
if (configs.length > 0) {
current_config = configs[0]
console.log(current_config)
removeSubscription(current_config.id);
} else {
console.log('App does not have a webhook config.')
}
})
}
function removeSubscription(config_id) {
// request options
var request_options = {
url: 'https://api.twitter.com/1.1/account_activity/webhooks/' + config_id + '/subscriptions.json',
oauth: twitter_oauth
}
// DELETE request to remove subscription
request.delete(request_options, function (error, response, body) {
if (response.statusCode == 204) {
console.log('Subscription removed.')
deleteConfig(config_id)
} else {
console.log('User has not authorized your app or subscription not found.')
deleteConfig(config_id)
}
})
}
function deleteConfig(config_id) {
// request options
var request_options = {
url: 'https://api.twitter.com/1.1/account_activity/webhooks/' + config_id + '.json',
oauth: twitter_oauth
}
// DELETE request to remove webhook config
request.del(request_options, function (error, response, body) {
if (error || response.statusCode != 204) {
console.log('Error deleting webhook config.')
return
} else {
console.log('Webhook config deleted.')
}
})
}
getConfig()
@jcipriano
Copy link
Author

jcipriano commented Nov 16, 2017

  1. Run npm install request
  2. Add app keys to script
  3. Run node delete-webhook-config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment