☰
instagram-private-api 数据分析:深入解析 InsightsServicePostResponseReach 接口与帖子触达量(Reach)指标
2026/10/16 3:35:11 网站建设 项目流程
  • 后端

【免费下载链接】instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.

项目地址:https://gitcode.com/gh_mirrors/in/instagram-private-api
点击查看免费下载

导读

在 instagram-private-api(NodeJS Instagram private API SDK,TypeScript 编写)中,InsightsServicePostResponseReach是帖子数据分析链路中的核心接口之一,承载着"触达量(Reach)"这一关键业务指标的结构化定义。本文将以该接口为主干,结合 insights.service.post.response.ts、insights.service.ts 等源码,完整讲解其字段语义、在整棵响应对象树中的位置、获取方式,以及与reach_count、impressions等相邻指标的区别,帮助你准确解析 Instagram 商业账号的单帖数据洞察(Post Insights)。

一、接口定位:帖子洞察响应树中的"触达"节点

InsightsServicePostResponseReach位于帖子洞察响应的深层嵌套结构中。从 insights.service.post.response.ts 的源码可以看到,一次帖子洞察请求的返回对象以InsightsServicePostResponseRootObject为根,访问路径为:

InsightsServicePostResponseRootObject └── data InsightsServicePostResponseData └── media InsightsServicePostResponseMedia └── inline_insights_node InsightsServicePostResponseInline_insights_node └── metrics InsightsServicePostResponseMetrics └── reach InsightsServicePostResponseReach ← 本文主角

从源码结构看,reach与reach_count、impression_count、impressions、share_count、profile_actions、owner_account_follows_count、owner_profile_views_count、hashtags_impressions同属 InsightsServicePostResponseMetrics 下的平行指标字段(定义于 insights.service.post.response.ts:36-45),而reach是其中唯一一个以嵌套对象而非标量数字形式呈现的字段,这一点决定了它在解析时需要额外一层结构处理。

二、接口定义与字段详解

InsightsServicePostResponseReach的定义位于 insights.service.post.response.ts:76-79,全文如下:

export interface InsightsServicePostResponseReach { value: number; follow_status: InsightsServicePostResponseFollow_status; }

2.1value: number—— 触达总量

  • 类型:number。
  • 语义:表示该帖子的触达量(Reach),即看过这条内容的去重后独立账号数。与"展示次数(Impressions)"会重复计数不同,Reach 更贴近真实触达人数。
  • 来源依据:定义于 insights.service.post.response.ts:77。

2.2follow_status: InsightsServicePostResponseFollow_status—— 按关注关系拆解的触达构成

  • 类型:InsightsServicePostResponseFollow_status,其内部只有一个字段:
export interface InsightsServicePostResponseFollow_status { nodes: InsightsServicePostResponseNodesItem[]; }

定义于 insights.service.post.response.ts:80-82。

  • 语义推断:从字段命名和结构可以推断,该字段将value这个触达总量按"观看者与账号所有者之间的关注关系"进一步拆解,用于回答诸如"有多少触达来自粉丝、多少来自非粉丝"之类的归因问题。value与follow_status.nodes中各项的数值之间存在聚合与细分的关系。

2.3nodes中每一项InsightsServicePostResponseNodesItem的结构

follow_status.nodes数组的每个元素复用通用的节点结构 InsightsServicePostResponseNodesItem,定义于 insights.service.post.response.ts:53-57:

export interface InsightsServicePostResponseNodesItem { __typename: string; value: number; name?: string; // 可选字段 }
字段类型说明
__typenamestringGraphQL 节点类型标识,用于区分该节点属于哪一类数据点
valuenumber该节点的数值,如某类关注关系下的触达人数
namestring(可选)节点名称标签,通常标识该数据点的业务含义

同样的NodesItem结构在Impressions.surfaces.nodes(按展示位置/渠道拆解)、Share_count、Profile_actions等指标中被反复复用,是整套 Insights 响应体系中通用的"数值+标签"数据点载体。

三、如何获取该数据:InsightsService.post()调用链

要拿到包含reach的响应,需要在已登录状态下调用InsightsService的post()方法(服务类继承自Repository,由 src/core/client.ts:84 通过public insights = new InsightsService(this)挂载在IgApiClient实例上):

import { IgApiClient } from 'instagram-private-api'; const ig = new IgApiClient(); ig.state.generateDevice('你的用户名'); // 登录后: const response = await ig.insights.post('MEDIA_ID'); // 取触达量 const reach = response.data.media.inline_insights_node.metrics.reach; console.log(reach.value); console.log(reach.follow_status.nodes);

3.1 底层 GraphQL 请求的实现

post()方法本身只是参数封装,真正的请求由 ads.repository.ts 的graphQL()方法发出(定义于 insights.service.ts:27-41):

public post(mediaId: string): Promise<InsightsServicePostResponseRootObject> { return this.client.ads.graphQL<InsightsServicePostResponseRootObject>({ surface: { name: 'post', friendlyName: 'IgInsightsPostInsightsQuery', }, documentId: '2009845309144121', variables: { query_params: { access_token: '', id: mediaId, }, }, }); }

对应的请求配置类型为 graphql-request.options.ts 中的GraphQLRequestOptions,其关键字段含义如下:

字段说明
surface.name数据面名称,此处为'post',取值类型定义见InsightsSurface
surface.friendlyNameGraphQL 操作的友好名称,此处为'IgInsightsPostInsightsQuery'
documentIdInstagram 服务端对应的 GraphQL 文档 ID,帖子洞察固定为'2009845309144121'
variables.query_params.id目标媒体 ID
variables.query_params.access_token商业数据接口的访问令牌,此处 SDK 默认传空字符串

3.2 请求的最终形态

ads.graphQL()会把上述配置拼接成一次对POST /api/v1/ads/graphql/的请求,query string 携带locale、vc_policy: 'insights_policy'、surface,表单中携带doc_id、fb_api_caller_class: 'RelayModern'、fb_api_req_friendly_name以及 JSON 序列化后的variables(见 ads.repository.ts:5-26)。这意味着reach数据本质上来自 Instagram 的广告/数据洞察 GraphQL 端点,而非普通的信息流接口。

四、关键指标辨析:reach与reach_count、impressions的差异

在 InsightsServicePostResponseMetrics 中同时存在三个容易混淆的指标,理解它们的区别是正确使用本文接口的前提:

指标类型语义
reach.value嵌套对象触达量(去重后的独立观看账号数),并带follow_status关注关系拆解
reach_countnumber触达量标量形式,即与reach.value同值的简化数字(定义于 insights.service.post.response.ts:38)
impressions嵌套对象展示次数(含重复曝光),带surfaces按展示位置拆解
impression_countnumber展示次数的标量形式
  • reach与impressions的典型关系是:展示次数 ≥ 触达量,因为同一账号可被多次曝光但只计一次触达。
  • 当只需要一个数字做聚合或落库时,直接用metrics.reach_count即可;当需要做归因分析(如"多少触达来自关注者")时,则必须解析metrics.reach.follow_status.nodes。

五、实战:解析follow_status做触达归因

以下示例展示如何遍历follow_status.nodes输出触达构成:

const metrics = response.data.media.inline_insights_node.metrics; const reach = metrics.reach; // 1. 触达总量 console.log(`总触达:${reach.value}`); // 2. 按关注状态拆解 for (const node of reach.follow_status.nodes) { console.log(`[${node.__typename}] ${node.name ?? '(无标签)'} = ${node.value}`); }

对返回的nodes数组,可结合__typename与name字段区分不同分类(如关注者/非关注者等数据点);由于name是可选的,编写健壮代码时应使用node.name ?? ''做兜底。

六、使用前提与注意事项

  1. 账号权限:InsightsServicePostResponseRootObject来自商业/创作者数据洞察接口。从仓库多处响应类型可见can_see_organic_insights、show_insights_terms等权限相关字段(如 media.repository.configure.response.ts:55-56),说明这类数据通常面向可查看有机洞察的账号开放,普通账号可能拿不到有效数据。
  2. 媒体 ID 格式:post()接收的是字符串形式的媒体 ID(MEDIA_ID),可通过media.info()等接口或帖子实体获得。
  3. 登录态依赖:请求链路依赖client.state中维护的 cookie 与设备信息,调用前必须完成ig.account.login()登录。
  4. 数据可用性:inline_insights_node.error字段类型为null(见 insights.service.post.response.ts:33),即 SDK 当前版本约定正常响应中该节点不携带错误信息;若未来服务端返回异常,仍需做好运行时校验。

七、关联能力延伸

  • 若想一次性获取多条帖子的洞察摘要(含每条帖子的reach_count、impression_count等标量指标),可改用 posts-insights.feed.ts 提供的PostsInsightsFeed分页流,其响应中的PostsInsightsFeedResponseMetrics(见 posts-insights.feed.response.ts:50-57)同样包含触达相关字段。
  • 账号级整体洞察(粉丝增长、内容表现等)则对应InsightsService.account(),其返回类型为 InsightsServiceAccountResponseRootObject。
  • 所有 Insights 响应类型均从 src/responses/index.ts 统一导出,可在引入时直接使用InsightsServicePostResponseRootObject、InsightsServicePostResponseReach等类型获得编译期类型校验。

总结

InsightsServicePostResponseReach是 instagram-private-api 帖子洞察数据中触达量指标的类型契约:value提供去重的触达总数,follow_status.nodes提供按关注关系拆解的构成明细。配合InsightsService.post()→AdsRepository.graphQL()的调用链,你可以在已登录商业账号的前提下,用类型安全的方式完成从"拉取帖子洞察"到"解析触达归因"的完整数据流程。

  • 后端

【免费下载链接】instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.

项目地址:https://gitcode.com/gh_mirrors/in/instagram-private-api
点击查看免费下载
上一篇:【免费下载】 Mac环境下Go语言开发环境配置指南(基于sb2nov/mac-setup)
下一篇:深入理解unjs/nitro中的任务系统

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询