@ fetcher-sh/ api (英语)
开发者友好客户端 获取器.sh —— 说 111个网上数据终端点 横跨Twitter/X,YouTube,TikTok,Instagram,Reddit,Google搜索,Google地图,Google新闻,Google Play,App Store,和Yelp. 将其作为国家预防机制 图书馆 或一个 国 际。 。 。 .
每个终点都是平地 GET 返回一个稳定 { status, message, data } 信封上写着 以美元支付 x402 (韩语),或将所有11项服务中的单项预付余额——相同 bby_live_ 关键在任何地方都有作用.
先决条件
- 节点.js 18+ (使用内置)
fetch) (中文(简体) ). - 其中一个:
- 预付 API 密钥 (单位:千美元)
bby_live_...)——得到一个在 获取器.sh/上架,或 - A 类 钱包 在Base、Polygon、Arbitrum、Monad或Solana上持有几分USDC,以支付每笔拨打的x402(不需要钥匙).
- 预付 API 密钥 (单位:千美元)
安装
npm install @fetcher-sh/api
快速启动( 图书馆)
// ESM
import { Fetcher } from "@fetcher-sh/api";
// CommonJS
const { Fetcher } = require("@fetcher-sh/api");
const fetcher = new Fetcher({ apiKey: process.env.FETCHER_API_KEY });
// Search tweets
const tweets = await fetcher.twitter.search({ query: "x402" });
// Look up an Instagram profile by handle
const profile = await fetcher.instagram.userByHandle("nasa");
// Clean Google web-search results
const serp = await fetcher.google.search({ query: "climate change" });
console.log(tweets, profile, serp);
默认情况下,每种方法只返回 data 字段。 过 { fullResponse: true } 来得到整个 { status, message, data } 信封上写着.
const env = await fetcher.reddit.searchPosts(
{ query: "bitcoin" },
{ fullResponse: true },
);
console.log(env.status, env.message, env.data);
如果 apiKey 被省略,它会回到 FETCHER_API_KEY 环境变量.
服务和方法
一个余额,11个服务。 每个命名空间地图1:1到 实时目录。 。 。 .
| 命名空间 | 通过 | 要点 |
|---|---|---|
| 推特/ X 页面存档备份,存于互联网档案馆 | fetcher.twitter 编号 : fetcher.x | search, (中文(简体) ), handle, (中文(简体) ), user, (中文(简体) ), userTweets, (中文(简体) ), userFollowers, (中文(简体) ), tweet, (中文(简体) ), tweetReplies, (中文(简体) ), trends, (中文(简体) ), listTweets |
| YouTube (英语) | fetcher.youtube | searchVideo, (中文(简体) ), video, (中文(简体) ), videoComments, (中文(简体) ), channel, (中文(简体) ), channelVideos, (中文(简体) ), trending, (中文(简体) ), playlistVideos |
| 叮当 | fetcher.tiktok | searchPosts, (中文(简体) ), postByUrl, (中文(简体) ), userByHandle, (中文(简体) ), userPosts, (中文(简体) ), hashtagPosts, (中文(简体) ), musicPosts |
| 内存 | fetcher.instagram | userByHandle, (中文(简体) ), user, (中文(简体) ), userPosts, (中文(简体) ), userReels, (中文(简体) ), userStories, (中文(简体) ), hashtagPosts, (中文(简体) ), postByCode |
| 编辑 | fetcher.reddit | searchPosts, (中文(简体) ), subredditPosts, (中文(简体) ), post, (中文(简体) ), postComments, (中文(简体) ), postsHot, (中文(简体) ), user, (中文(简体) ), userComments |
| 谷歌搜索 | fetcher.google | search |
| 谷歌地图 | fetcher.googleMaps | searchPlaces, (中文(简体) ), place, (中文(简体) ), placeReviews, (中文(简体) ), review |
| 谷歌新闻 | fetcher.googleNews | search, (中文(简体) ), latest, (中文(简体) ), world, (中文(简体) ), business, (中文(简体) ), technology, (中文(简体) ), topic, (中文(简体) ), decodeArticleUrl |
| 谷歌播放 | fetcher.googlePlay | searchApps, (中文(简体) ), app, (中文(简体) ), appReviews, (中文(简体) ), appPermissions, (中文(简体) ), appDataSafety, (中文(简体) ), developer |
| 应用程序存储 | fetcher.appStore | searchApps, (中文(简体) ), app, (中文(简体) ), appReviews, (中文(简体) ), appSimilar, (中文(简体) ), bundle, (中文(简体) ), developer |
| 耶尔普 | fetcher.yelp | search, (中文(简体) ), place, (中文(简体) ), placeByHandle, (中文(简体) ), placeReviews |
普通出逃舱门
任何终点——即使没有指定助手的终点——都可以达到 get数字 :
await fetcher.get("/api/twitter/search", { params: { query: "x402" } });
await fetcher.get("/api/reddit/subreddit/programming/posts");
倾斜
贴出端点返回不透明 cursor。将它传回获取下一页:
let cursor: string | undefined;
do {
const page = await fetcher.twitter.userFollowers("44196397", {
fullResponse: true,
params: { cursor },
});
// ...process page.data...
cursor = (page.data as any)?.cursor;
} while (cursor);
用x402(无密钥)支付每个呼叫
跳过 API 密钥, 并通过一个 付款包 fetch 换句话说 客户端保持无依赖性——你带钱包:
import { Fetcher } from "@fetcher-sh/api";
import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const fetchWithPayment = wrapFetchWithPaymentFromConfig(fetch, {
schemes: ["eip155:8453", "eip155:137", "eip155:42161", "eip155:143"].map(
(network) => ({ network, client: new ExactEvmScheme(account) }),
),
});
const fetcher = new Fetcher({ fetch: fetchWithPayment });
const tweets = await fetcher.twitter.search({ query: "x402" }); // 402 → sign → retry, automatically
气体是赞助的,因此钱包不需要本地的代币——只要USDC在任何被支持的链上.
贷项
// Read the shared balance (needs an API key)
const balance = await fetcher.credits.balance();
console.log(balance.balance_usd);
// Top up (x402-paid; requires a payment-wrapped fetch). The first top-up
// returns the bby_live_ key EXACTLY ONCE — store it, it cannot be recovered.
const result = await fetcher.credits.topup(5);
console.log(result.key);
处理错误
每个非-2xx响应都会发出一个 FetcherError 带有状态、解析后的信封和助手:
import { FetcherError } from "@fetcher-sh/api";
try {
await fetcher.twitter.search({ query: "x402" });
} catch (err) {
if (err instanceof FetcherError) {
if (err.isTopupRequired) console.error("Out of credits — top up.");
else if (err.isUnauthorized) console.error("Bad or rotated API key.");
else if (err.isPaymentRequired) console.error("x402 payment required.");
else console.error(err.status, err.message);
}
}
国 际
从命令行安装到全球使用 :
npm install -g @fetcher-sh/api
设置
# Store your API key (saved to ~/.fetcher-sh/config.json)
fetcher init --token bby_live_xxx
# Or set it as an environment variable
export FETCHER_API_KEY=bby_live_xxx
# Or pass it per command
fetcher balance --token bby_live_xxx
图标
# Shortcuts for each service's hero endpoint
fetcher twitter-search "x402"
fetcher youtube-search "lofi hip hop"
fetcher tiktok-search "cats"
fetcher instagram-user nasa
fetcher reddit-search "bitcoin"
fetcher google-search "climate change"
fetcher google-maps-search "coffee near me"
fetcher google-news-search "artificial intelligence"
fetcher googleplay-apps "notes"
fetcher appstore-apps "notes"
fetcher yelp-search "coffee" --location "San Francisco"
# Call ANY endpoint by path; extra --flags become query params
fetcher get /api/twitter/user/44196397/tweets --cursor abc123
fetcher get /api/reddit/subreddit/programming/posts
# Credits
fetcher balance
fetcher topup --amount 5 # needs an x402 wallet — see notes
# Explore the catalog
fetcher services
fetcher endpoints twitter
输出选项
fetcher twitter-search "x402" # pretty JSON (default)
fetcher twitter-search "x402" --json # compact JSON
fetcher twitter-search "x402" --jsonl # one object per line (arrays)
fetcher twitter-search "x402" --output out.json
fetcher get /api/x/y --debug # show raw error bodies
全球旗帜
| 旗帜 | 说明 |
|---|---|
--token <key> | API 密钥( E)bby_live_...; 覆盖 env 配置( c) |
--base-url <url> | 覆盖 API 基础 URL |
--json | 压缩 JSON 输出 |
--jsonl | 每行1个JSON对象(仅限阵列) |
--output <file> | 将输出写入文件 |
--<key> <value> | 任何额外的查询参数(例如. --cursor, (中文(简体) ), --location(中文(简体) ) |
API 参考
new Fetcher(options?)
| 选项 | 类型 | 默认 | 说明 |
|---|---|---|---|
apiKey | string | FETCHER_API_KEY 环境 | 预付信贷钥匙bby_live_...(中文(简体) ) |
baseUrl | string | https://fetcher.sh | API 基础 URL |
fetch | FetchLike | 全球 fetch | 自定义抓取( 如 x402 付款被包) |
timeout | number | 30000 | 默认请求超时( ms) |
headers | object | {} | 在每个请求中增加标题 |
请求选项( 每一次呼叫)
| 选项 | 类型 | 说明 |
|---|---|---|
fullResponse | boolean | 返回时 { status, message, data } 而不是仅仅 data |
params | object | 额外查询参数 |
timeout | number | 请求超时( 以毫秒计) |
signal | AbortSignal | 取消请求 |
静态
Fetcher.endpoints()——111个出价终点的完整目录.Fetcher.services()——每个服务元数据(主机,计数,汇总).Fetcher.priceOf(path)——路径(支持的路径)的美元价格.
页:1
- 设计时只读. 每个终点都是
GET——没有写作,后面写作,也没有文章. - 无利率限制. 您的平衡( 或钱包) 是自然回压 .
- 上游故障时不退. 在交货前解决.
- 这个 非正式 fearer.sh的客户端,它本身是一个独立的代理,与X,TikTok,Meta,Google,Yelp或Apple没有隶属关系.
许可证
麻省理工学院