npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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

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