@pm25/moreapi-sdk
v1.0.0
Published
TypeScript SDK for MoreAPI
Readme
MoreAPI TypeScript SDK
MoreAPI 是一个强大的多平台社交媒体 API TypeScript SDK,支持 9 大主流平台,提供 143 个 API 接口,让您轻松获取社交媒体数据。
🚀 特性
- 🎯 多平台支持: 抖音、小红书、快手、哔哩哔哩、微博、TikTok、Lemon8、YouTube、榜单
- 📊 143 个接口: 覆盖视频、用户、评论、搜索、直播等全场景
- 🔒 严格对照: 所有接口参数严格按照官方文档实现
- ⚡ 高性能: 基于 Axios 的统一 HTTP 客户端,连接复用,高效稳定
- 🛡️ 类型安全: 完整的 TypeScript 类型定义,提供优秀的开发体验和代码提示
📦 安装
npm install moreapi-sdk
# or
yarn add moreapi-sdk
# or
pnpm add moreapi-sdk🏁 快速开始
基础使用
import { DouYin, XHS, KuaiShou } from "moreapi-sdk";
// 初始化API(请替换为您的真实token)
const config = { token: "your_api_token" };
const dy = new DouYin(config);
const xhs = new XHS(config);
const ks = new KuaiShou(config);
async function main() {
// 抖音:获取视频详情
const videoInfo = await dy.awemeDetail({ aweme_id: "7493493472100355362" });
console.log(videoInfo);
// 小红书:搜索笔记
const notes = await xhs.searchNote({ keyword: "护肤心得", page: 1 });
console.log(notes);
// 快手:获取用户信息
const userInfo = await ks.userData({
user_id: "user123",
cookie: "your_cookie",
});
console.log(userInfo);
}
main();中文搜索示例
import { DouYin } from "moreapi-sdk";
const dy = new DouYin({ token: "your_api_token" });
async function search() {
// 完美支持中文关键词
const searchResults = await dy.generalSearch({
keyword: "美食分享",
count: 12,
publish_time: "7", // 最近一周
content_type: "0", // 综合
});
console.log(searchResults);
// 搜索用户
const users = await dy.searchUser({ keyword: "美妆博主" });
console.log(users);
// 话题搜索
const topics = await dy.searchTopic({ keyword: "旅游攻略", count: 18 });
console.log(topics);
}
search();🌟 支持平台
| 平台 | 接口数量 | 主要功能 | | -------------------------- | -------- | ------------------------------------------ | | 🎵 抖音 (DouYin) | 56 个 | 视频详情、用户信息、搜索、评论、直播、热榜 | | 📝 小红书 (XHS) | 29 个 | 笔记详情、用户信息、搜索、评论、登录 | | ⚡ 快手 (KuaiShou) | 9 个 | 视频详情、用户信息、搜索、评论 | | 📺 哔哩哔哩 (Bilibili) | 10 个 | 视频数据、用户信息、搜索、下载 | | 🐦 微博 (WeiBo) | 10 个 | 用户详情、微博内容、评论、搜索 | | 🎬 TikTok | 8 个 | 视频详情、用户数据、评论、搜索 | | 🍋 Lemon8 | 3 个 | 视频详情、用户信息、用户作品 | | 📹 YouTube | 5 个 | 视频数据、评论、搜索、播放列表 | | 📊 榜单 (Billboard) | 13 个 | 各类排行榜、热门数据、用户分析 |
📚 详细文档
抖音 API 示例
import { DouYin } from "moreapi-sdk";
const dy = new DouYin({ token: "your_token" });
async function douyinExamples() {
// 视频相关
const video = await dy.awemeDetail({ aweme_id: "video_id" });
const video_v3 = await dy.awemeDetailV3({ share_text: "分享链接" });
const videos = await dy.multipleAwemeDetail({ item_ids: "[id1,id2,id3]" });
// 用户相关
const user = await dy.userData({ sec_user_id: "user_id" });
const user_posts = await dy.userPost({ sec_user_id: "user_id", count: 20 });
const user_analysis = await dy.userProductData({
sec_user_id: "user_id",
count: 30,
});
// 搜索功能
const search_all = await dy.generalSearch({ keyword: "关键词", count: 12 });
const search_videos = await dy.searchVideo({ keyword: "视频", count: 18 });
const search_users = await dy.searchUser({ keyword: "用户" });
const search_music = await dy.searchMusic({ keyword: "音乐" });
// 评论功能
const comments = await dy.videoComment({ aweme_id: "video_id", count: 20 });
const sub_comments = await dy.videoSubComment({
aweme_id: "video_id",
comment_id: "comment_id",
});
// 直播相关
const live_room = await dy.liveRoomData({ web_rid: "room_id" });
const live_users = await dy.liveUserData({ web_rid: "room_id" });
}小红书 API 示例
import { XHS } from "moreapi-sdk";
const xhs = new XHS({ token: "your_token" });
async function xhsExamples() {
// 笔记相关
const note = await xhs.noteDetail({
note_id: "note_id",
xsec_token: "token",
cookie: "your_cookie",
});
const note_v2 = await xhs.noteDetailV2({ share_text: "分享链接" });
const note_comments = await xhs.noteComment({ note_id: "note_id" });
// 用户相关
const user = await xhs.userDetail({ user_id: "user_id" });
const user_posts = await xhs.userPost({
user_id: "user_id",
cookie: "cookie",
});
// 搜索功能
const notes = await xhs.searchNote({ keyword: "搜索词", page: 1 });
const users = await xhs.searchUser({ keyword: "用户名" });
const suggestions = await xhs.searchSuggestion({ keyword: "关键词" });
// 登录相关
const qr_code = await xhs.loginQrCode();
const login_status = await xhs.checkLogin({ qr_id: "qr_id", code: "code" });
}⚙️ 高级配置
代理设置
所有 API 方法的参数都接受一个 proxy 字段。
// HTTP代理
const result = await dy.awemeDetail({
aweme_id: "id",
proxy: "http://proxy:8080",
});
// SOCKS5代理
const searchResult = await dy.searchVideo({
keyword: "test",
proxy: "socks5://proxy:1080",
});
// 不使用代理
const userData = await dy.userData({ sec_user_id: "id", proxy: false });Cookie 支持
对于需要登录的接口,可以在参数中传入 cookie。
const user_favorite = await dy.userFavorite({
sec_user_id: "user_id",
cookie: "your_login_cookie",
});
const xhs_user_posts = await xhs.userPost({
user_id: "user_id",
cookie: "xhs_cookie",
});错误处理
SDK 中的所有方法都是异步的,并返回 Promise。您可以使用 try...catch 来处理可能发生的错误。
try {
const result = await dy.awemeDetail({ aweme_id: "invalid_id" });
} catch (e) {
console.error(`API调用失败: ${e}`);
// 处理错误
}🔗 获取 API Token
- 访问 MoreAPI 官网
- 注册账号并登录
- 在控制台获取您的 API Token
- 查看 API 文档 了解详细使用方法
🤝 贡献
欢迎提交 Issue 和 Pull Request!
📄 许可证
MIT License
📞 联系我们
- 官网:https://api.moreapi.cn
- 文档:https://ziopqu50k5.apifox.cn/
- 邮箱:[email protected]
- GitHub:https://github.com/liulu1550/MoreAPI
⭐ 如果这个项目对您有帮助,请给我们一个 Star!
