Socket
Socket
Sign inDemoInstall

tweets.js

Package Overview
Dependencies
8
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    tweets.js

a easy to use client for the twitter api


Version published
Weekly downloads
1
Maintainers
1
Install size
605 kB
Created
Weekly downloads
 

Readme

Source

Installing

You can install the tweets.js package using the following command

npm i tweets.js

support

  • Discord Support server

usage

Getting the token

  • Create an app on https://apps.twitter.com/
  • Grab the Consumer Key (API Key) and Consumer Secret (API Secret) from Keys and Access Tokens
  • Make sure you set the right access level for your app
  • If you want to use user-based authentication, grab the access token key and secret as well

Using the package is pretty easy

setting up

const { client }= require('tweets.js');
const  bot = new  tweet({
consumer_key:  "",
consumer_secret:  "",
access_token:  "",
access_token_secret:  ""
// get these by applying for developer access on twitter
});

Example

tweeting

bot.tweet('hello from tweets.js').then(console.log).catch(console.error)

Streams

  • Using the default settings

  • A stream emitter is ready on startup by default, you will just have to call <client>.start(parameters) for it to be activated

  • Do not use all the events in the below code without knowing what they are for, only use ones you need


const parameters = {
  follow: "1238451949000888322", // @typicalninja (my twitter id)
};

const stream = bot.start(parameters);

// Stream is ready
stream.on('ready', (res) => {
  console.log('Stream ready');
});

// o new tweet for our parameters was posted
stream.on("tweet", tweet => console.log(tweet));

// a tweet was deleted
stream.on('tweetDelete', (deletedTweet) => console.log(deletedTweet));

// a chuck was received
stream.on('raw', (data, type) => console.log('[', type, ']', '-', data));

// good idea to listen for these errors
stream.on('error', (err) => console.log(err));

// Not important
stream.on("ping", () => console.log("ping"))

// emitted when stream ends
stream.on("end", () => console.log(`Stream ended`))

// if the client reconnects due to pintTimeout exceeding (or other, but mostly pintTimeout exceeding)
stream.on('reconnect', () => console.log('Reconnecting.....'));

// Remove if not making a stream for debug purpose, logs everything the client does behind the scence
stream.on('debug', (message) => console.log(message));

search for users

// returns a array
bot.searchUsers('typicalNinja').catch(console.log).then(users => {
  console.log(users[0].id);
});

find all the methods in our docs here

Errors

Read-only application cannot POST

If you receive a error like above, change the permission for you app from dev portal to read and write from read

img

  • Make sure to reset your access Token and Secret

img

  • it should be equal to below image

img

New version is here!!!

  • supports streams
  • Updated code

Credit

Keywords

FAQs

Last updated on 13 Jun 2021

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc