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

threads-ts

v1.3.0

Published

Strongly typed, full-featured, light, versatile Threads API client.

Downloads

42

Readme

threads-ts

A TypeScript SDK for the Threads API, making it easy to interact with Threads in your TypeScript/JavaScript projects.

npm version License: MIT

Official Threads Documentation:

https://developers.facebook.com/docs/threads

Table of Contents

Installation

Install the package using npm:

npm install threads-ts

Or using yarn:

yarn add threads-ts

Usage

First, import and initialize the ThreadsAPI class:

import { ThreadsAPI, ThreadsAPIConfig } from 'threads-ts';

const config: ThreadsAPIConfig = {
  clientId: 'YOUR_CLIENT_ID',
  clientSecret: 'YOUR_CLIENT_SECRET',
  redirectUri: 'YOUR_REDIRECT_URI',
  scope: ['threads_basic', 'threads_content_publish']
};

const threadsAPI = new ThreadsAPI(config);

Authentication

Generate an authorization URL:

const authUrl = threadsAPI.getAuthorizationUrl();
console.log('Authorize your app:', authUrl);

Exchange the authorization code for an access token:

const code = 'AUTHORIZATION_CODE';
const tokenResponse = await threadsAPI.getAccessToken(code);
console.log('Access Token:', tokenResponse.access_token);

// Set the access token for future requests
threadsAPI.setAccessToken(tokenResponse.access_token);

Creating and Publishing a Thread

const userId = 'USER_ID';

// Create a media container
const creationId = await threadsAPI.createMediaContainer({
  userId,
  mediaType: 'TEXT',
  text: 'Hello, Threads!'
});

// Publish the media container
const threadId = await threadsAPI.publishMediaContainer({
  userId,
  creationId
});

console.log('Published Thread ID:', threadId);

Retrieving User Threads

const userId = 'USER_ID';
const fields = ['id', 'text', 'username', 'timestamp'];

const userThreads = await threadsAPI.getUserThreads({
  userId,
  fields,
  options: { limit: 10 }
});

console.log('User Threads:', userThreads);

Retrieving User Profile

const userId = 'USER_ID';
const fields = ['id', 'username', 'name', 'threads_profile_picture_url'];

const userProfile = await threadsAPI.getUserProfile({
  userId,
  fields
});

console.log('User Profile:', userProfile);

Retrieving Replies to a Thread

const mediaId = 'THREAD_ID';
const fields = ['id', 'text', 'username', 'timestamp'];

const replies = await threadsAPI.getReplies({
  mediaId,
  fields
});

console.log('Replies:', replies);

Responding to a Reply

const userId = 'USER_ID';
const replyToId = 'THREAD_ID_TO_REPLY_TO';

const replyId = await threadsAPI.respondToReply({
  userId,
  mediaType: 'TEXT',
  text: 'This is my response!',
  replyToId
});

console.log('Reply ID:', replyId);

Retrieving Media Insights

const mediaId = 'THREAD_ID';
const metrics = ['engagement', 'impressions', 'reach'];

const insights = await threadsAPI.getMediaInsights({
  mediaId,
  metrics
});

console.log('Media Insights:', insights);

API Reference

For a complete list of available methods and their parameters, please refer to the API documentation.

Contributing

We welcome contributions to the threads-ts SDK! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Please make sure to update tests as appropriate and adhere to the existing coding style.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

Acknowledgements

  • Thanks to the Threads team for providing the API
  • All the contributors who have helped improve this SDK

Made with ❤️ by solojungle