快速入门

5分钟内开始使用TCG Price Lookup API。


1. 获取API密钥

tcgpricelookup.com注册,从控制台获取免费API密钥。免费计划包含每日200次请求,无需信用卡。

登录后,前往控制台 → API密钥部分。密钥格式如下:

tcg_live_sk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

请妥善保管此密钥。不要将其提交到版本控制系统,也不要在客户端代码中暴露它。

2. 安装SDK

选择您偏好的语言,安装官方SDK:

# JavaScript / TypeScript
npm install tcglookup

# Python
pip install tcglookup

# Go
go get github.com/TCG-Price-Lookup/tcglookup-go

# Rust
cargo add tcglookup

# PHP
composer require tcg-price-lookup/tcglookup

所有SDK都会自动处理认证、请求序列化、错误解析和速率限制响应头。

3. 发送第一个请求

以下是各支持语言的最简示例:

// JavaScript / TypeScript
import { TCGLookup } from 'tcglookup';

const tcg = new TCGLookup({ apiKey: 'your-api-key' });

const results = await tcg.search('charizard', { game: 'pokemon', limit: 5 });
console.log(results.data);
// → 包含实时市场价格的卡牌对象数组
# Python
from tcglookup import TCGLookup

tcg = TCGLookup(api_key='your-api-key')
results = tcg.search('charizard', game='pokemon', limit=5)
print(results.data)
// Go
client := tcglookup.NewClient("your-api-key")
results, _ := client.Search("charizard", &tcglookup.SearchParams{Game: "pokemon"})

4. 理解响应格式

成功的响应结构如下:

{
  "data": [
    {
      "id": "pokemon-base1-4",
      "name": "Charizard",
      "game": "pokemon",
      "set": { "name": "Base Set", "code": "base1" },
      "rarity": "Rare Holo",
      "prices": {
        "nearMint": {
          "market": 450.00,
          "tcgplayer": 445.00,
          "ebay": 455.00
        },
        "lightlyPlayed": {
          "market": 380.00
        }
      }
    }
  ],
  "total": 12,
  "limit": 5,
  "offset": 0
}

5. 后续步骤