You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Pokemon TCG Ruby SDK获取卡牌集图片遇阻求助

解决Pokemon TCG Ruby SDK获取卡牌图片的问题

你当前的代码仅获取了卡牌集(Set)的元数据,而卡牌图片信息存储在单卡(Card)对象中,需要通过卡集ID关联查询对应的卡牌列表,再从每个卡牌对象中提取图片链接。

修改后的实现代码

Pokemon.configure do |config|
  config.api_key = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
end

# 获取第一个标准合法的卡集
target_set = Pokemon::Set.where(q: 'legalities.standard:legal').first

# 根据卡集ID查询该集下的所有卡牌
cards_in_set = Pokemon::Card.where(set: target_set.id)

# 遍历卡牌,提取图片链接
cards_in_set.each do |card|
  # 卡牌图片有两种尺寸:small(小图)和large(大图)
  puts "卡牌名称: #{card.name}"
  puts "小图链接: #{card.images['small']}"
  puts "大图链接: #{card.images['large']}"
  puts "---"
end

关键说明

  • 卡集(Set)对象仅包含卡集的基本信息(如名称、代码、发布日期等),不直接存储卡牌图片;
  • 通过Pokemon::Card.where(set: 卡集ID)可以筛选出目标卡集下的所有卡牌;
  • 每个Card对象的images属性是哈希结构,包含small和large两个字段,对应不同尺寸的图片URL。

分页处理(可选)

如果目标卡集包含大量卡牌,SDK支持分页查询避免一次性加载过多数据:

# 分页查询,每页20条,取第1页
cards_in_set = Pokemon::Card.where(set: target_set.id).page(1).page_size(20)

内容的提问来源于stack exchange,提问作者mustafaalomer711

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 11:21:07