Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

tw-activity

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tw-activity

A library for the Twitter Account Activity API. https://developer.twitter.com/en/docs/accounts-and-users/subscribe-account-activity/overview

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

tw-activity

NPM

MIT License Build Status Greenkeeper badge codecov

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);
  }
}

More detail

API document

API document is here

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": ""
}

Keywords

twitter

FAQs

Package last updated on 19 Nov 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts