资讯详情

instagram-private-api 账号洞察(Insights)中 account_discovery_graph 响应结构深度解析

📅 2026/10/15 2:18:29 | 华诺云谱 👁 阅读
instagram-private-api 账号洞察(Insights)中 account_discovery_graph 响应结构深度解析
后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载本文聚焦 NodeJS 的 TypeScript 开源 SDKinstagram-private-api中账号数据洞察Account Insights响应的一个关键子结构——InsightsServiceAccountResponseAccount_discovery_graph。该接口承载 Instagram 商业账号“账户发现表现”如主页访问、展示、触达等趋势图的节点数据是调用InsightsService.account()后解析IgInsightsAccountInsightsWithTabsQueryGraphQL 响应时必须理解的核心类型之一。读完本文你将掌握该接口的定义、在整个响应树中的位置、其节点与数据点类型的完整字段语义以及如何在真实项目中安全取值与绘制趋势图。一、account_discovery_graph 在响应树中的位置InsightsServiceAccountResponseAccount_discovery_graph并不是一个孤立类型它是账号洞察响应深层路径中的一个字段。依据 src/responses/insights.service.account.response.ts 中从根对象到该字段的类型嵌套完整的访问路径如下InsightsServiceAccountResponseRootObject └── data: InsightsServiceAccountResponseData └── user: InsightsServiceAccountResponseUser └── business_manager: InsightsServiceAccountResponseBusiness_manager └── account_insights_unit: InsightsServiceAccountResponseAccount_insights_unit └── account_discovery_graph: InsightsServiceAccountResponseAccount_discovery_graph ← 本文主题 └── nodes: InsightsServiceAccountResponseNodesItem[]也就是说要拿到该结构需要逐层访问response.data.user.business_manager.account_insights_unit.account_discovery_graph.nodes;与account_discovery_graph平级、同处account_insights_unit之下的洞察字段还包括account_actions_graph账户行为总览图、metric_graph指标图、graph以及profile_visits_metric_count、impressions_metric_count、reach_metric_count等计数与环比增量字段它们在 接口文档 InsightsServiceAccountResponseAccount_insights_unit 中有完整罗列。account_discovery_graph与这些字段共同构成了账号“发现Discovery”维度的表现数据。二、接口定义与字段语义2.1 接口本体InsightsServiceAccountResponseAccount_discovery_graph的完整定义见 docs/interfaces/responses/InsightsServiceAccountResponseAccount_discovery_graph.md源码位于 src/responses/insights.service.account.response.tsexport interface InsightsServiceAccountResponseAccount_discovery_graph { nodes: InsightsServiceAccountResponseNodesItem[]; }该接口仅包含一个必填属性属性类型必填含义nodesInsightsServiceAccountResponseNodesItem[]是描述账号发现表现的一组图节点每个节点代表一条图线或一个聚合子图2.2 节点类型 InsightsServiceAccountResponseNodesItemnodes数组中的每个元素类型为InsightsServiceAccountResponseNodesItem源码见 src/responses/insights.service.account.response.ts其字段如下export interface InsightsServiceAccountResponseNodesItem { graph_name?: string; data_points?: InsightsServiceAccountResponseDataPointsItem[]; __typename?: string; organic?: InsightsServiceAccountResponseOrganic; delta?: null; total?: number; }属性类型必填说明graph_namestring可选图名称标识用于区分该节点是哪类发现趋势如主页访问、展示、触达等data_pointsInsightsServiceAccountResponseDataPointsItem[]可选该图线的时序数据点列表是绘制趋势图的核心数据__typenamestring可选GraphQL 节点类型名由 Instagram 后端返回可用于类型分发/调试organicInsightsServiceAccountResponseOrganic可选自然流量非付费相关的聚合信息deltanull可选环比变化量在类型定义中固定为null访问时可直接判空totalnumber可选该节点的总量值若后端返回2.3 数据点类型 InsightsServiceAccountResponseDataPointsItemdata_points中的每个元素类型为InsightsServiceAccountResponseDataPointsItem源码见 src/responses/insights.service.account.response.tsexport interface InsightsServiceAccountResponseDataPointsItem { label: string; value: number; }属性类型必填说明labelstring是数据点的时间/分桶标签例如日期或小时区间valuenumber是该数据点的数值例如当日主页访问量2.4 自然流量子结构 InsightsServiceAccountResponseOrganic当节点携带organic时其类型为InsightsServiceAccountResponseOrganic源码见 src/responses/insights.service.account.response.tsexport interface InsightsServiceAccountResponseOrganic { value: number; status: string; }属性类型必填说明valuenumber是自然流量指标数值statusstring是状态标识字符串如active等具体取值由后端决定三、数据从何而来InsightsService.account() 调用链account_discovery_graph数据由账号级洞察查询产生入口为 src/services/insights.service.ts 中的InsightsService.account()方法public account(options: AccountInsightsOptions): PromiseInsightsServiceAccountResponseRootObject { return this.client.ads.graphQLInsightsServiceAccountResponseRootObject({ surface: { name: account, friendlyName: IgInsightsAccountInsightsWithTabsQuery, }, documentId: 2552829571413315, variables: { IgInsightsGridMediaImage_SIZE: options.gridMediaSize || 256, activityTab: options.activityTab || true, audienceTab: options.audienceTab || true, contentTab: options.contentTab || true, query_params: { access_token: options.accessToken || , id: options.userId || this.client.state.cookieUserId, }, timezone: Environment/Local, }, }); }要点说明底层通过this.client.ads.graphQL发起 Instagram 广告/商业平台的 GraphQL 请求documentId固定为2552829571413315对应IgInsightsAccountInsightsWithTabsQuery默认以当前登录用户的 cookie 用户 IDthis.client.state.cookieUserId作为查询目标timezone固定为Environment/Local数据点标签会按本地时区解释。因此account_discovery_graph是 Instagram 后端针对上述查询返回的结构化数据SDK 只负责类型化封装不做额外加工——这意味着你看到的字段布局data.user.business_manager.account_insights_unit.account_discovery_graph直接反映了后端 GraphQL 响应的嵌套形态。四、请求参数 AccountInsightsOptions 详解调用account()时传入的参数类型定义在 src/types/insights.options.tsexport interface AccountInsightsOptions { gridMediaSize?: number; userId?: string; accessToken?: string; // all will default to true contentTab?: boolean; activityTab?: boolean; audienceTab?: boolean; }参数类型默认值说明gridMediaSizenumber256媒体网格缩略图尺寸userIdstring当前登录用户 cookie ID要查询洞察的目标账号 IDaccessTokenstring可选的访问令牌一般场景留空即可contentTabbooleantrue是否请求内容Content标签页数据activityTabbooleantrue是否请求行为Activity标签页数据account_actions_graph等与此相关audienceTabbooleantrue是否请求受众Audience标签页数据从源码可推断三个 Tab 开关默认全部为true因此默认响应中会包含account_discovery_graph所在的内容/发现类数据。若不需要某些 Tab可显式传false以减少响应体积。五、实战获取并消费 account_discovery_graph5.1 最小调用示例import { IgApiClient } from instagram-private-api; const ig new IgApiClient(); ig.state.generateDevice(username); // 先完成登录详见 examples/session.example.ts await ig.account.login(username, password); // 1) 拉取当前账号的洞察数据需为商业/创作者账号 const insights await ig.insights.account({}); // 2) 逐层定位 account_discovery_graph const discoveryGraph insights.data.user.business_manager.account_insights_unit.account_discovery_graph; // 3) 遍历节点输出每个发现趋势图的名称与数据点 for (const node of discoveryGraph.nodes) { console.log(graph: ${node.graph_name} (typename${node.__typename})); if (node.total ! undefined) { console.log( total: ${node.total}); } for (const point of node.data_points ?? []) { console.log( ${point.label}: ${point.value}); } }5.2 安全取值建议由于NodesItem中的大部分字段为可选graph_name、data_points、__typename、organic、total并且delta被固定类型化为null实际使用时应遵循对node.data_points使用空值合并或可选链node.data_points ?? []对delta直接按“无环比数据”处理判空即可它不可能是数值不要假设每个节点都含全部字段——organic与total是否返回取决于后端对具体图线的数据安排这从接口字段全部可选可以推断该数据结构仅在商业账号/创作者账号的洞察响应中可用普通个人账号的business_manager层级可能缺失访问前建议做存在性判断。5.3 与相邻洞察结构的对照account_discovery_graph属于账号维度洞察与其相邻或同源的结构还包括account_actions_graph账户行为趋势内部为total_count_graph.data_points见 接口文档 InsightsServiceAccountResponseAccount_actions_graphgraph与metric_graph通用图与指标图同样由nodes: InsightsServiceAccountResponseNodesItem[]构成impressions_metric_count/reach_metric_count展示与触达的计数及环比_delta。这些结构共享同一个NodesItem/DataPointsItem类型体系掌握本文的字段语义后可以无障碍地解析账号洞察中的所有图类数据。六、类型生态与相关文档索引account_discovery_graph所属的响应类型体系集中在响应模块索引 docs/modules/responses.md 中可继续深入阅读根对象InsightsServiceAccountResponseRootObject直接父级InsightsServiceAccountResponseAccount_insights_unit节点类型InsightsServiceAccountResponseNodesItem数据点类型InsightsServiceAccountResponseDataPointsItem自然流量子结构InsightsServiceAccountResponseOrganic对应的 TypeScript 定义全部位于 src/responses/insights.service.account.response.ts服务层实现见 src/services/insights.service.ts参数类型见 src/types/insights.options.ts。七、总结InsightsServiceAccountResponseAccount_discovery_graph是instagram-private-api中账号发现表现洞察的核心响应结构本质是一个只包含nodes数组的图容器每个节点由graph_name、data_points、organic、total、delta等可选字段描述一条趋势图线。它由InsightsService.account()通过IgInsightsAccountInsightsWithTabsQuerydocumentId2552829571413315获取深层嵌套于data.user.business_manager.account_insights_unit之下。实际开发中理解其节点/数据点类型的可选字段语义配合可选链与判空处理即可稳定地解析并可视化账号的主页访问、展示、触达等发现趋势数据。赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐Audiveris 乐谱编辑实用技巧选择框、增时点、装饰音与三连音的 6 个高效操作指南Audiveris 乐谱编辑实用技巧选择框、增时点、装饰音与三连音的 6 个高效操作指南 Audiveris光学乐谱识别 OMR 引擎在自动转写后用户往后端instagram-private-api 高亮封面裁剪图响应结构HighlightsRepositoryCreateReelResponseCropped_image_version 深度解析instagram private api 高亮封面裁剪图响应结构HighlightsRepositoryCreateReelResponseCropped_后端instagram-private-api 账户信息响应结构解析AccountRepositoryCurrentUserResponseRootObject 接口完整指南instagram private api 账户信息响应结构解析AccountRepositoryCurrentUserResponseRootObject后端上一篇3DGS模型压缩与优化如何在保持质量的同时减少75%内存占用下一篇Kafka-King现代化Kafka图形化管理工具的技术深度解析创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
📝

华诺云谱内容团队

资深建站顾问 · 行业研究员

10年+企业数字化服务经验,专注智能建站、SEO优化与品牌营销,持续输出建站技巧、行业洞察与营销干货,已帮助5000+企业实现数字化增长。

你可能需要的服务

订阅华诺云谱资讯周报

每周一封,精选建站技巧、SEO与营销干货,直达邮箱。已有 8,000+ 企业主订阅,助你少走弯路。

↑