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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@hkai-ai/twitter-data-fetch

v1.0.19

Published

推特接口API

Readme

Twitter-Data-Fetch

该仓库为获取推特数据的接口封装代码。

请注意,现在的它是一个封装的函数库。你应该调用封装好的函数进行调用。

NOTE: 该 package 预计在很长一段时间里都不会进行维护了。推荐使用 https://github.com/fa0311/twitter-openapi-typescript 这个库。

0. 目前支持的接口 Support

  • 列表的最新推文数据,对应推特接口为/ListLatestTweetsTimeline
  • 某用户的最新 12 条推文数据,对应推特接口为 /UserTweets

1. 安装 Installation

请注意,现在的它是一个封装的函数库

如果你想通过 npm packages 安装,直接运行:

npm install @hk-artificial-intelligence-association/twitter-data-fetch@latest

即可。

如果你想通过 Github packages 的镜像安装,你应该首先在引入的工程根目录下添加 .npmrc 文件引入 @hk-artificial-intelligence-association 的正确 registry:

@hk-artificial-intelligence-association:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken= the token

而后运行命令安装:

npm install @hk-artificial-intelligence-association/twitter-data-fetch@latest

如果你没有安装 playwright ,你还需要运行这些命令进行安装:

npm install playwright
npx playwright install

核心的获取功能函数都是依赖于 playwright 的,因此,如果你需要获取 twitter 的数据,应当安装 playwright 。

2. 示例使用 Sample/Usage

对于封装的函数调用:

import { loginToGetCookies } from "@hk-artificial-intelligence-association/twitter-data-fetch";
import { getTwitterListNewlyTweetsWithCookies } from "@hk-artificial-intelligence-association/twitter-data-fetch";
import { getTwitterUserNewlyTweetsWithCookies } from "@hk-artificial-intelligence-association/twitter-data-fetch";
import { simplyParseTweetEntity } from "@hk-artificial-intelligence-association/twitter-data-fetch";
import { analyzeTypeOFTweetSimpleParsedResult } from "@hk-artificial-intelligence-association/twitter-data-fetch";
import { analyzeTwitterSimpleParsedResult } from "@hk-artificial-intelligence-association/twitter-data-fetch";

import dotenv from 'dotenv'

async function main() {
    dotenv.config()
    const cookies = await loginToGetCookies(process.env.TWITTER_ID || 'UserLoginName',process.env.TWITTER_PASSWORD || 'UserPassword',10000)
    const listId = '1795638097327358182'
    const userId = 'LeeWendao'
    const listTweets = await getTwitterListNewlyTweetsWithCookies(listId,cookies)
    /**
     * 只有12条哦~
     */
    const userTweets = await getTwitterUserNewlyTweetsWithCookies(userId,cookies)
    /**
     * 原始数据比较杂,可以使用解析函数对结果进行简单的解析
     * 该解析会保留推文的原始信息数据
     */
    const parsedListTweets = listTweets.map(t=>simplyParseTweetEntity(t))
    /**
     * 可以使用分析函数判断推文的类型:原创,转发 etc.
     */
    const analyzedListTweets = parsedListTweets.map(t=>analyzeTypeOFTweetSimpleParsedResult(t))
    /**
     * 可以使用分析函数提取推文的内容,提取的内容会是形如这样的字符串:
     * "@xx 于 某年某月某日 转发了 @yy 于 某年某月某日发布 的推文 \n----\n @yy 的推文内容:略"
     */
    const analyzedTweetsContent = parsedListTweets.map(t=>analyzeTwitterSimpleParsedResult(t))
}

main()