后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载导读PostsInsightsFeedResponseInline_insights_node是 instagram-private-apiNodeJS Instagram 私域 API SDKTypeScript 编写中「帖文数据洞察」Posts Insights响应模型的核心内嵌节点。它承载单条帖文的曝光、触达、主页浏览量、关注增长、分享与主页行为等聚合指标是读取「主页置顶帖子Top Posts」数据分析结果的直接入口。读完本文你将掌握该接口的字段语义、在完整响应树中的位置、底层 GraphQL 请求链路以及如何用PostsInsightsFeed分页拉取并消费这些洞察数据。1. 该接口在项目中的定位在 instagram-private-api 中帖文数据洞察通过PostsInsightsFeed源码位于 src/feeds/posts-insights.feed.ts拉取其响应类型定义在 src/responses/posts-insights.feed.response.ts。PostsInsightsFeedResponseInline_insights_node是该响应文件中的一个内嵌节点接口位于整棵响应树的深处PostsInsightsFeedResponseRootObject └── data ── PostsInsightsFeedResponseData └── user ── PostsInsightsFeedResponseUser └── business_manager ── PostsInsightsFeedResponseBusiness_manager └── top_posts_unit ── PostsInsightsFeedResponseTop_posts_unit └── top_posts ── PostsInsightsFeedResponseTop_posts └── edges[] ── PostsInsightsFeedResponseEdgesItem └── node ── PostsInsightsFeedResponseNode └── inline_insights_node ── PostsInsightsFeedResponseInline_insights_node本文主题 ├── metrics ── PostsInsightsFeedResponseMetrics └── state: string从源码结构看每个edges元素代表一篇帖文node而inline_insights_node就是该帖文在帖子网格中的内联洞察摘要——即 Instagram 商业账户「专业面板Professional Dashboard」中每篇帖子卡片直接展示的那组核心数据。前置条件帖子洞察Posts Insights属于商业/创作者账户的专属能力非商业账户调用相关 GraphQL 接口通常无法返回有效数据。2. 接口定义与字段说明PostsInsightsFeedResponseInline_insights_node只有两个字段定义于 src/responses/posts-insights.feed.response.tsexport interface PostsInsightsFeedResponseInline_insights_node { metrics: PostsInsightsFeedResponseMetrics; state: string; }字段类型必填含义metricsPostsInsightsFeedResponseMetrics是聚合的帖子表现指标见下节statestring是该洞察节点的状态标识例如ok或异常状态字符串metrics字段展开为PostsInsightsFeedResponseMetrics包含六个核心指标定义于 src/responses/posts-insights.feed.response.ts指标字段类型含义impression_countnumber帖文总曝光次数被展示的次数reach_countnumber触达人数实际看到帖文的独立账户数owner_account_follows_countnumber因该帖文产生的新关注数转化关注owner_profile_views_countnumber因该帖文带来的主页浏览量profile_actionsPostsInsightsFeedResponseProfile_actions用户在帖子页面执行的主页操作行为集合share_countPostsInsightsFeedResponseShare_count分享次数嵌套于tray.value其中两个复合类型继续向下展开profile_actionssrc/responses/posts-insights.feed.response.ts内部为actions.edges[]每条 edge 复用PostsInsightsFeedResponseEdgesItem结构其node即PostsInsightsFeedResponseNode上的name动作名称如FOLLOW、BIO_LINK_CLICK与value次数字段组合起来便构成一组「动作类型 → 次数」的键值对对应 src/types/insights.options.ts 中dataOrdering所列的FOLLOW、BIO_LINK_CLICK、GET_DIRECTIONS、EMAIL、TEXT等行为类型。share_countsrc/responses/posts-insights.feed.response.ts通过tray.valuenumber给出分享总次数。2.1 字段类型完整性说明metrics下的impression_count、reach_count、owner_account_follows_count、owner_profile_views_count为必填的number而profile_actions与share_count为必填的对象类型。作为对比其父级PostsInsightsFeedResponseNode中的like_count、comment_count、engagement、save_count等字段均为可选?video_view_count被声明为null字面量类型src/responses/posts-insights.feed.response.ts这体现了 Instagram GraphQL 响应中不同字段的可选性差异——消费端代码在读取任何可选字段前都应做空值防御。3. 完整响应示例结合响应树与字段定义一次帖子洞察请求的完整 JSON 结构示意如下数值仅为示意{ data: { user: { id: 123456789, business_manager: { top_posts_unit: { top_posts: { edges: [ { node: { instagram_media_id: 987654321, instagram_media_type: IMAGE, image: { uri: https://... }, creation_time: 1620000000, comment_count: 12, engagement: 345, like_count: 300, save_count: 33, shopping_product_click_count: 0, shopping_outbound_click_count: 0, inline_insights_node: { metrics: { impression_count: 12500, reach_count: 9800, owner_account_follows_count: 25, owner_profile_views_count: 210, profile_actions: { actions: { edges: [ { node: { name: FOLLOW, value: 25 } }, { node: { name: BIO_LINK_CLICK, value: 18 } } ] } }, share_count: { tray: { value: 9 } } }, state: ok }, id: 987654321, __typename: IGMedia } } ], page_info: { end_cursor: QVFJUUFC..., has_next_page: false } } } } } } }4. 底层请求链路它是如何被拉取到的inline_insights_node不会凭空出现它由PostsInsightsFeed发起一次 Ads GraphQL 请求获得。关键调用链如下入口工厂ig.feed.postsInsightsFeed(options)src/core/feed.factory.ts构造PostsInsightsFeed实例options类型为PostsInsightsFeedOptions。发起请求PostsInsightsFeed.request()src/feeds/posts-insights.feed.ts调用client.ads.graphQL()携带surface.friendlyName: IgInsightsPostGridSurfaceQuerydocumentId: 1981884911894608variablescount: 15、分页cursor、IgInsightsGridMediaImage_SIZE: 256、queryParams.id client.state.cookieUserId并展开用户传入的options。底层执行AdsRepository.graphQL()src/repositories/ads.repository.ts向/api/v1/ads/graphql/发送 POST表单中包含doc_id、variablesJSON 序列化以及vc_policy: insights_policy等参数。状态推进每次请求后statesettersrc/feeds/posts-insights.feed.ts从page_info.end_cursor与has_next_page更新分页游标与moreAvailable支撑后续翻页。提取结果items()src/feeds/posts-insights.feed.ts返回edges数组其中每个edge.node.inline_insights_node即本文接口的实例。4.1 请求参数详解PostsInsightsFeedOptionssrc/types/insights.options.ts提供三组控制参数timeframe必填统计时间窗取值为ONE_WEEK | ONE_MONTH | THREE_MONTHS | SIX_MONTHS | ONE_YEAR | TWO_YEARSdataOrdering必填帖子排序依据取值包括CALL、COMMENT_COUNT、EMAIL、ENGAGEMENT_COUNT、FOLLOW、GET_DIRECTIONS、IMPRESSION_COUNT、LIKE_COUNT、PROFILE_VIEW、REACH_COUNT、SAVE_COUNT、SHARE_COUNT、TEXT、BIO_LINK_CLICK——与inline_insights_node.metrics.profile_actions中的行为类型相互呼应postType必填帖子类型过滤取值为ALL | IMAGE | VIDEO | CAROUSEL_V2 | SHOPPING。5. 实战消费帖子洞察数据以下示例演示如何分页拉取全部置顶帖子的洞察指标并逐条输出import { IgApiClient } from instagram-private-api; const ig new IgApiClient(); ig.state.generateDevice(username); // 登录与状态恢复逻辑省略可参考 examples/session.example.ts const feed ig.feed.postsInsightsFeed({ timeframe: ONE_MONTH, dataOrdering: REACH_COUNT, // 按触达人数排序 postType: ALL, }); for await (const edge of feed) { const { node } edge; const insights node.inline_insights_node; console.log(帖文 ${node.instagram_media_id}${node.instagram_media_type}); console.log( 曝光 ${insights.metrics.impression_count}触达 ${insights.metrics.reach_count}); console.log( 新增关注 ${insights.metrics.owner_account_follows_count}主页浏览 ${insights.metrics.owner_profile_views_count}); console.log( 分享 ${insights.metrics.share_count.tray.value}); for (const action of insights.metrics.profile_actions.actions.edges) { console.log( 主页行为 ${action.node.name}: ${action.node.value}); } console.log( 洞察状态 state${insights.state}); }说明要点for await...of依赖 src/core/feed.ts 暴露的items$Observable 与isMoreAvailable()src/core/feed.ts驱动的自动翻页逻辑每次翻页由 src/core/feed.ts 的observable()内部使用lifeomic/attempt的retry实现限流重试默认minDelay/delay为 60000ms最大重试 10 次对 400/429/500/502 状态码自动退避高并发拉取时建议通过第二个参数传入自定义attemptOptionsstate字段可用于快速判断该帖文洞察数据是否有效如是否为okprofile_actions.actions.edges的node可能同时携带name与value读取前建议先判空。6. 与其他洞察接口的关系inline_insights_node属于「帖子网格Post Grid」级别的内联摘要与 instagram-private-api 中其他洞察能力互补InsightsService.account()src/services/insights.service.ts通过IgInsightsAccountInsightsWithTabsQuery获取账户级聚合洞察含 content/activity/audience 三个标签页对应响应类型见 InsightsServiceAccountResponseInsightsService.post(mediaId)src/services/insights.service.ts针对单条帖文调用IgInsightsPostInsightsQuery获取更完整的帖子级报告InsightsService.story()与igtv()src/services/insights.service.ts分别覆盖 Story 与 IGTV 的洞察查询StoriesInsightsFeed以 Feed 形式分页拉取 Story 洞察源码见 src/feeds/stories-insights.feed.ts。实际使用中可以把PostsInsightsFeed的inline_insights_node当作「Top Posts 榜单摘要」配合InsightsService.post()下钻到单帖完整报告形成「榜单 → 明细」两级分析链路。7. 常见注意事项商业账户门槛洞察数据接口面向商业/创作者账户普通个人账户请求通常会失败或返回空数据请求频率洞察 GraphQL 走/api/v1/ads/graphql/请遵循 Feed 内置的重试与限流策略避免触发 Instagram 的风控可选字段防御node上除__typename外多为可选字段inline_insights_node本身也是可选的src/responses/posts-insights.feed.response.ts消费端务必判空分页游标PostsInsightsFeed的翻页依赖page_info.end_cursor序列化/反序列化 Feed 状态可借助 Feed.serialize 与deserializesrc/core/feed.ts实现断点续拉session 前提所有洞察请求都基于已登录的IgApiClient会话ig.state.cookieUserId作为默认查询账户 ID可参考 examples/session.example.ts 完成登录与状态持久化。8. 参考文件索引接口定义src/responses/posts-insights.feed.response.tsinline_insights_node、L50-L57metricsFeed 实现src/feeds/posts-insights.feed.ts请求参数类型src/types/insights.options.tsGraphQL 底层src/repositories/ads.repository.ts工厂方法src/core/feed.factory.ts文档索引responses 模块、feeds 模块赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐AutoHotkey DllCall 深度解析如何调用任意 DLL 函数突破语言边界 AutoHotkey DllCall 深度解析如何调用任意 DLL 函数突破语言边界 AutoHotkey DllCall 详解 本文面向 Windo后端instagram-private-api 帖子数据洞察PostsInsightsFeed 深度解析与实战指南instagram private api 帖子数据洞察PostsInsightsFeed 深度解析与实战指南 导读 PostsInsightsFeed 是后端如何彻底搞懂 Dem 故障管理DTC 记录、存储与清除的完整指南如何彻底搞懂 Dem 故障管理DTC 记录、存储与清除的完整指南 在车载 ECU 开发中 Dem故障管理模块 是安全车控操作系统 BSW 的核心组件。E后端上一篇5分钟上手react-native-swiper从基础轮播到高级交互的全攻略下一篇Grumpy中的字节处理Go []byte与Python bytes创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
阅读完成 · 觉得有帮助?