Created
November 13, 2017 19:31
-
-
Save jcipriano/f8592dc9eebaf53f76c325a5432e5658 to your computer and use it in GitHub Desktop.
Retrieves webhook subscriptions for Twitter Account Activity API.
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 nconf = require('nconf') | |
var request = require('request') | |
// load config | |
nconf.file({ file: 'config.json' }).env() | |
// twitter authentication | |
var twitter_oauth = { | |
consumer_key: 'redacted', | |
consumer_secret: 'redacted', | |
token: 'redacted', | |
token_secret: 'redacted' | |
} | |
var WEBHOOK_ID = 'redacted' | |
/** | |
* Retrieves bearer token | |
*/ | |
function get_bearer_token () { | |
var request_options = { | |
url: 'https://api.twitter.com/oauth2/token', | |
method: 'POST', | |
auth: { | |
user: twitter_oauth.consumer_key, | |
pass: twitter_oauth.consumer_secret | |
}, | |
form: { | |
'grant_type': 'client_credentials' | |
} | |
} | |
request(request_options, function(error, response) { | |
var json = JSON.parse(response.body); | |
get_subscription_list(json.access_token); | |
}) | |
} | |
/** | |
* Retrieves webhook subscriptions | |
*/ | |
function get_subscription_list (bearer_token) { | |
request({ | |
url: 'https://api.twitter.com/1.1/account_activity/webhooks/' + WEBHOOK_ID + '/subscriptions/list.json', | |
auth: { | |
'bearer': bearer_token | |
} | |
}, function(err, res) { | |
console.log(res.body); | |
}); | |
} | |
get_bearer_token() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment