instagram-private-api 主题探索响应中的 Launch_information 接口:商品 Drops 发售信息的结构与解析

原创2026-10-15 18:20:541,342 阅读
文章标签:后端

instagram-private-api 主题探索响应中的 Launch_information 接口:商品 Drops 发售信息的结构与解析

导读

TopicalExploreFeedResponseLaunch_information 是 instagram-private-api(NodeJS Instagram 私有 API SDK,TypeScript 编写)在「主题探索 Feed」(topical explore)响应中用于描述商品限时发售(Drops)信息的接口。本文以该接口为切入点,完整梳理它的 4 个字段定义、在响应对象树中的嵌套位置(Product → launch_information)、以及如何通过 TopicalExploreFeed 在实际代码中拿到并解析这批数据,并给出对应的源码证据路径,帮助开发者在购物类内容抓取、Drops 活动监测等场景中快速上手。

接口定位:出现在哪里

在 src/responses/topical-explore.feed.response.ts 中,TopicalExploreFeedResponseLaunch_information 定义在 第 230~235 行:

export interface TopicalExploreFeedResponseLaunch_information {
    launch_date: number;
    has_launched: boolean;
    is_ig_exclusive: boolean;
    drops_campaign_id: string;
}

它并不是一个独立的顶层响应,而是作为 TopicalExploreFeedResponseProduct 的可选属性 launch_information? 出现(第 214 行)。而 Product 又是购物标签(product_tags)体系中的核心结构,整个嵌套关系可以概括为:

TopicalExploreFeedResponseRootObject
└─ sectional_items[] → layout_content
   └─ medias[] / fill_items[] → media
      └─ product_tags.in[] → TopicalExploreFeedResponseInItem
         └─ product? → TopicalExploreFeedResponseProduct
            └─ launch_information? → TopicalExploreFeedResponseLaunch_information

从命名和字段语义可以推断,该结构对应 Instagram 购物体系中的 Drops(品牌限时发售)活动元数据:只有参与 Drops 的商品才会携带 launch_information,普通商品该字段为 undefined。

该接口与 TopicalExploreFeedResponseProduct、TopicalExploreFeedResponseInItem 等一起,通过 src/responses/index.ts:103 的 export * from './topical-explore.feed.response' 从 SDK 顶层统一导出,因此在应用代码中可以直接使用 import { TopicalExploreFeedResponseLaunch_information } from 'instagram-private-api'。

字段详解

原文档定义的全部 4 个属性如下表:

属性名 TypeScript 类型 含义(结合语义推断)
launch_date number Drops 发售启动的时间戳
has_launched boolean 当前是否已经开售
is_ig_exclusive boolean 是否为 Instagram 平台独占发售
drops_campaign_id string 对应的 Drops 活动(campaign)ID

launch_date: number

发售时间点,类型为 number。结合 Instagram 后端响应的通用惯例,这类字段通常是 Unix 时间戳(秒级)。若需要展示为本地时间,可在拿到原始 number 后乘以 1000 转换为毫秒再传给 Date,例如:

const launchInfo = product.launch_information;
if (launchInfo) {
  const launchAt = new Date(launchInfo.launch_date * 1000);
  console.log(launchAt.toISOString(), launchInfo.has_launched);
}

has_launched: boolean

标记该 Drops 是否已经开始。对于「抢购提醒 / 开售状态轮询」类应用,该字段可作为开售与否的直接判断依据。

is_ig_exclusive: boolean

是否仅限 Instagram 内发售。可用于区分全渠道发售与 IG 专属发售,帮助做内容筛选或数据统计。

drops_campaign_id: string

Drops 活动的唯一标识。可用于将不同商品关联到同一个 campaign,或与外部活动数据做联表分析。

字段的可选性与运行时判断

接口挂在 Product 上的形态是 launch_information?: TopicalExploreFeedResponseLaunch_information(见 TopicalExploreFeedResponseProduct 接口文档),即普通商品没有该字段。因此所有访问 launch_information 的代码都应先做存在性判断:

function readLaunchInfo(product: TopicalExploreFeedResponseProduct) {
  const info = product.launch_information;
  if (!info) return null; // 非 Drops 商品
  return {
    campaignId: info.drops_campaign_id,
    launched: info.has_launched,
    igExclusive: info.is_ig_exclusive,
    date: new Date(info.launch_date * 1000),
  };
}

如何在实际代码中获取这些数据

获取 launch_information 的完整链路是:先通过 Feed 拿到主题探索内容,再遍历其中的商品标签。SDK 提供了两个入口:

入口一:FeedFactory.topicalExplore()

工厂方法定义在 src/core/feed.factory.ts:322-326,支持注入 sessionId、clusterId、lat、lng、module 等选项:

const feed = ig.feed.topicalExplore();
const sectionalItems = await feed.items();

TopicalExploreFeed 本身定义在 src/feeds/topical-explore.feed.ts,其 request() 方法会请求 GET /api/v1/discover/topical_explore/,并携带 is_prefetch、omit_cover_media、use_sectional_payload、cluster_id、session_id 等查询参数。

入口二:DiscoverRepository.topicalExplore()

仓库方法定义在 src/repositories/discover.repository.ts:19,以 is_prefetch: true 的方式调用同一端点,适合预加载场景。此外它还被 src/services/simulate.service.ts:42 纳入 simulate(模拟登录后冷启动行为)的请求集合中。

遍历示例

拿到 sectional_items 后,需要逐层进入 layout_content,再对 medias / fill_items 里的 media 读取 product_tags.in[].product:

const feed = ig.feed.topicalExplore();
const sections = await feed.items();

for (const section of sections) {
  const layout = section.layout_content;
  const medias = [
    ...(layout.medias ?? []).map(m => m.media),
    ...(layout.fill_items ?? []).map(f => f.media),
  ];
  for (const media of medias) {
    for (const tag of media.product_tags?.in ?? []) {
      const product = tag.product;
      if (!product?.launch_information) continue;
      const { drops_campaign_id, has_launched, is_ig_exclusive, launch_date } =
        product.launch_information;
      console.log({ drops_campaign_id, has_launched, is_ig_exclusive, launch_date });
    }
  }
}

接口在响应模型中的关联结构

为方便按需扩展读取,这里补充 launch_information 周边的几个关键接口(均在同一响应文件中定义):

实践注意事项

  1. 字段存在性:launch_information 是可选的,只有 Drops 商品才会出现;读取前务必判空,避免 TypeError。
  2. 时间戳单位:launch_date 为 number,判断开售时间时需要结合单位(秒/毫秒)处理;如需精确校准,可在真实环境抓包一次进行确认。
  3. 分页:TopicalExploreFeed 继承自 Feed 基类,more_available 为真时可通过 max_id 继续拉取,覆盖更多 section 以扩大商品覆盖范围。
  4. 接口版本绑定:以上字段与行号以当前仓库 src/responses/topical-explore.feed.response.ts 为准;Instagram 端接口可能随时调整,建议在应用中做容错处理(例如全部字段可选化解析)。

总结

TopicalExploreFeedResponseLaunch_information 虽然只是响应模型中的一个 4 字段小接口,但它精准对应 Instagram 商品 Drops 发售元数据,是理解主题探索 Feed 购物内容结构的关键一环。结合 响应类型文件、TopicalExploreFeed 请求实现 与 FeedFactory.topicalExplore(),开发者可以快速实现「按 campaign 聚合 Drops 商品」「监测开售状态变化」等真实业务功能。

登录后查看全文
instagram-private-api