tw-activity
v1.1.1
Published
A library for the Twitter Account Activity API. https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/overview
Downloads
6
Readme
tw-activity
A library for the Twitter Account Activity API. https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/overview
How to use
Use in your shell
# install
npm install -g tw-activity
tw-activity --help
Use in your code
# install package
npm install tw-activity --save
// index.js
const {
createWebhook
} = require("tw-activity")
const url = "https://your.domain/webhook"
const oauth = {
// your consumer key...
}
createWebhook(url, oauth)
.then(resp => console.log(resp.body)) // may got `"[]"`
.catch(error => console.error(error))
Reject on error status code
You can use rejectOnErrorStatus
to catch errors when you
receive the error status code (4xx or 5xx).
Default is false.
createWebhook(url, oauth, true) // <- if got status code 4xx or 5xx.
.then(resp => console.log(resp.body))
.catch(error => console.error(error)) // <- you will catch the error.
For more example. you can see the /bin/tw-activity
Use in your server side code
You can also generate response of your Webhook server.
const { responseToken } = require("tw-activity").crc
function serverWebhookGetEndpoint(request, response) {
const { crc_token } = request.query;
if (crc_token) {
const response_token = responseToken(crc_token, "your consumer secret")
response.status(200).send({
response_token
});
} else {
console.error("crc_token missing from request.");
response.sendStatus(400);
}
}
API document
CLI usage
tw-activity [command]
Commands:
tw-activity --help Show help [aliases: -h, help]
tw-activity create-wh <url> Create webhook config
tw-activity delete-wh <id> Delete webhook config
tw-activity get-wh Get webhook config
tw-activity add-sub <id> Add subscription
tw-activity delete-sub <id> Delete subscription
tw-activity get-sub <id> Get subscriptions
tw-activity trigger <id> Tritter CRC request
Options:
--version Show version number [boolean]
--help Show help [boolean]
--config Twitter config file [default: "./config.json"]
--verbose Be verbose [boolean] [default: false]
Twitter config
Pass the twitter config json file.
--config [path]
{
"TWITTER_CONSUMER_KEY": "",
"TWITTER_CONSUMER_SECRET": "",
"TWITTER_ACCESS_TOKEN": "",
"TWITTER_ACCESS_TOKEN_SECRET": ""
}