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

@kworq/x-api-post

v0.1.3

Published

A Node.js module for posting tweets with media (images, videos, GIFs) to X (formerly Twitter) using the API. It handles authentication, media uploading, and posting tweets.

Downloads

168

Readme

X / Twitter Media Upload and Posting

Overview

This Node.js module provides functionality to post tweets with media (images, videos, GIFs) to Twitter using Twitter's API. It handles the authentication, media uploading (including chunked uploads for large files), and posting of tweets with the uploaded media.

Requirements

  • Node.js v20.0.0 or higher
  • X / Twitter Developer Account with API keys

Installation

npm install @kworq/x-api-post

Working with source

  1. Clone the repository or copy the code into your project directory.
  2. Install the required dependencies using npm:
npm install

Run source

node --import ./esm-loader.mjs app.ts

Configuration

Before using this module, you need to set up the configuration with your Twitter API credentials. The configuration object should have the following properties:

  • X_API_KEY
  • X_API_SECRET
  • X_API_ACCESS_TOKEN
  • X_API_ACCESS_TOKEN_SECRET

Class

XApiClient

A class to handle posting tweets with media to Twitter.

Constructor

Creates an instance of XApiClient.

new XApiClient(config)
Parameters:
  • config: Configuration object containing Twitter API credentials.

Methods

postTweetWithMedia(text, mediaUrls)

Posts a tweet with the specified text and media.

Parameters:
  • text: The text of the tweet.
  • mediaUrls: An array of media URLs to upload and attach to the tweet.

Usage Example

import XApiClient from '@kworq/x-api-post';

const config = {
  X_API_KEY: 'your_api_key',
  X_API_SECRET: 'your_api_secret',
  X_API_ACCESS_TOKEN: 'your_access_token',
  X_API_ACCESS_TOKEN_SECRET: 'your_access_token_secret',
};

const text = "Hello, world!";
const mediaUrls = ["https://www.w3schools.com/html/mov_bbb.mp4"];

const client = new XApiClient(config);

client.postTweetWithMedia(text, mediaUrls)
  .then((response) => console.log(response))
  .catch((error) => console.error("Error posting tweet:", error));

Notes

  • Ensure you have valid Twitter API credentials.
  • Media files larger than 5MB will be uploaded in chunks.
  • The media upload process includes initialization, appending chunks, finalizing, and checking the status.
  • This module requires Node.js v18.0.0 or higher to use the native fetch function.

License

This project is licensed under the MIT License.