Last active
November 16, 2017 19:01
-
-
Save jcipriano/8b5098b7f3af51aaa037107f01c95b4d to your computer and use it in GitHub Desktop.
Deletes an Account Activity API 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: '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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
npm install request
node delete-webhook-config.js