首页 / 资讯中心 / 文章详情

instagram-private-api 内联子评论响应结构详解:MediaInlineChildCommentsFeedResponseChildCommentsItem 接口深度剖析

instagram-private-api 内联子评论响应结构详解:MediaInlineChildCommentsFeedResponseChildCommentsItem 接口深度剖析 ★ FEATURED ARTICLE
后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载本文围绕 instagram-private-apiTypeScript 编写的 NodeJS Instagram 私有 API SDK中的MediaInlineChildCommentsFeedResponseChildCommentsItem接口展开系统讲解评论“楼中楼”inline child comments数据的字段语义、与之配套的父评论与用户类型以及底层 Feed 分页拉取机制。读完本文你将能够准确解析该 SDK 返回的子评论数据结构并能在自己的脚本中利用ig.feed.mediaInlineChildComments()完整地遍历某条评论的全部回复。一、接口定位Instagram 评论楼中楼数据模型在 Instagram 的评论体系中一条帖子的评论区既包含顶层评论也允许用户在顶层评论下继续“回复”形成两级评论树。MediaInlineChildCommentsFeedResponseChildCommentsItem正是 instagram-private-api 为描述**顶层评论的子评论回复**而定义的核心响应接口之一。它声明于响应类型文件 src/responses/media.inline-child-comments.feed.response.ts并通过 src/responses/index.ts 的export *从包入口统一导出可被业务代码直接 import 使用。从源码结构看它与其他三个接口共同组成完整的“子评论”响应体系接口语义定义行MediaInlineChildCommentsFeedResponseRootObject子评论分页响应根对象src/responses/media.inline-child-comments.feed.response.tsMediaInlineChildCommentsFeedResponseParent_comment被回复的父评论src/responses/media.inline-child-comments.feed.response.tsMediaInlineChildCommentsFeedResponseChildCommentsItem单条子评论本文主角src/responses/media.inline-child-comments.feed.response.tsMediaInlineChildCommentsFeedResponseUser评论发布者用户信息src/responses/media.inline-child-comments.feed.response.ts对应到 TypeDoc 文档模块中可依次查看 RootObject 文档、Parent_comment 文档、ChildCommentsItem 文档 与 User 文档。二、属性全解析15 个字段的语义与类型原文档完整列出了MediaInlineChildCommentsFeedResponseChildCommentsItem的 15 个属性。下面按“身份标识 → 内容 → 时间 → 状态 → 互动数据 → 嵌套用户”分组逐一说明。2.1 身份标识字段pkstring。子评论的唯一主键primary key对应 Instagram 内部的评论 ID。注意它被定义为字符串用于在parent_comment_id、评论点赞等后续请求中回传标识。定义见 media.inline-child-comments.feed.response.ts:37。user_idnumber。评论发布者的用户 ID是数字类型与user.pk语义相同、格式不同两者可配合用于跨接口关联如拼接用户主页请求。定义见 media.inline-child-comments.feed.response.ts:38。parent_comment_idstring。该字段是“子评论”语义的关键指明本条回复隶属于哪一条顶层评论它应该与响应根对象中的parent_comment.pk一致可用于在客户端本地构建评论树、按父评论聚合回复。定义见 media.inline-child-comments.feed.response.ts:49。2.2 内容与类型字段textstring。子评论的正文文本。定义见 media.inline-child-comments.feed.response.ts:39。typenumber。评论的类型码。评论体系中的类型常量通常为固定数值如常规评论与特定系统评论对应不同取值SDK 原样透传该数值未做枚举映射。定义见 media.inline-child-comments.feed.response.ts:40。content_typestring。内容类型标识例如comment。定义见 media.inline-child-comments.feed.response.ts:43。2.3 时间字段created_atnumber。评论创建时间的 Unix 时间戳秒级本地展示可用。定义见 media.inline-child-comments.feed.response.ts:41。created_at_utcnumber。评论创建时间的UTC Unix 时间戳秒级。实践中通常优先使用created_at_utc换算为标准时间避免时区歧义。定义见 media.inline-child-comments.feed.response.ts:42。2.4 状态与标志字段statusstring。评论的当前状态正常情况多为Active之类的字符串已被删除或违规的评论会携带其他状态值。定义见 media.inline-child-comments.feed.response.ts:44。bit_flagsnumber。评论的位标志bit flags整数值用于编码一组布尔状态Instagram 客户端通过位掩码解析SDK 原样透传。定义见 media.inline-child-comments.feed.response.ts:45。did_report_as_spamboolean。当前登录账号是否已将该评论举报为垃圾内容为true时可用于前端界面高亮“已举报”状态。定义见 media.inline-child-comments.feed.response.ts:47。share_enabledboolean。该评论是否允许被分享转发为故事等。定义见 media.inline-child-comments.feed.response.ts:48。2.5 互动数据字段has_liked_commentboolean。当前登录账号是否已赞过该子评论可用于渲染点赞按钮的选中态。定义见 media.inline-child-comments.feed.response.ts:50。comment_like_countnumber。该子评论累计收到的点赞数。定义见 media.inline-child-comments.feed.response.ts:51。2.6 嵌套用户字段userMediaInlineChildCommentsFeedResponseUser。发布者的完整用户信息对象。该内嵌接口包含 7 个字段具体见 MediaInlineChildCommentsFeedResponseUser 文档 及源码 media.inline-child-comments.feed.response.ts:27-35字段类型说明pknumber用户数字 IDusernamestring用户名full_namestring用户显示名is_privateboolean是否为私密账号profile_pic_urlstring头像 URLprofile_pic_idstring可选头像图片 ID部分场景缺省is_verifiedboolean是否蓝 V 认证2.7 字段类型速查表interface MediaInlineChildCommentsFeedResponseChildCommentsItem { pk: string; // 子评论 ID user_id: number; // 发布者用户 ID text: string; // 评论文本 type: number; // 评论类型码 created_at: number; // 创建时间秒级时间戳 created_at_utc: number; // UTC 创建时间秒级时间戳 content_type: string; // 内容类型标识 status: string; // 评论状态 bit_flags: number; // 位标志 user: MediaInlineChildCommentsFeedResponseUser; // 发布者信息 did_report_as_spam: boolean; // 是否已举报 share_enabled: boolean; // 是否可分享 parent_comment_id: string; // 所属父评论 ID has_liked_comment: boolean; // 当前账号是否已点赞 comment_like_count: number; // 点赞总数 }三、父评论与根对象子评论的上下文子评论不是孤立数据它总是依附于某条顶层评论。接口MediaInlineChildCommentsFeedResponseRootObject提供了请求一次“内联子评论”端点后返回的完整上下文其字段见 RootObject 文档parent_commentMediaInlineChildCommentsFeedResponseParent_comment。被回复的父评论完整对象。child_commentsMediaInlineChildCommentsFeedResponseChildCommentsItem[]。当前页返回的子评论数组即items()的数据来源。child_comment_countnumber。该父评论下的子评论总数。has_more_tail_child_comments/has_more_head_child_commentsboolean。指示尾部/头部是否还有更多子评论是分页判断的依据之一。next_max_child_cursorstring。下一页的游标cursorFeed 用它驱动继续翻页。num_tail_child_commentsnumber。尾部剩余子评论数量。statusstring。响应状态。而MediaInlineChildCommentsFeedResponseParent_comment见 Parent_comment 文档与子评论拥有几乎完全一致的字段集合pk、user_id、text、type、时间戳、bit_flags、user、举报/分享/点赞等唯一区别是父评论没有parent_comment_id——因为父评论本身就是回复树的根节点。从字段结构上可以推断Instagram 将“顶层评论”与“子评论”建模为同构对象仅通过是否携带parent_comment_id来区分层级这解释了为什么两者在 SDK 中各自声明了一套几乎重复的接口。四、底层实现Feed 如何分页拉取子评论子评论接口由MediaInlineChildCommentsFeed负责拉取实现在 src/feeds/media.inline-child-comments.feed.ts。它是抽象基类FeedResponse, Item见 src/core/feed.ts的子类核心机制如下4.1 请求端点与参数public async request(): PromiseMediaInlineChildCommentsFeedResponseRootObject { const { body } await this.client.request.send({ url: /api/v1/media/${this.mediaId}/comments/${this.commentId}/inline_child_comments/, qs: { min_id: this.nextMinId, max_id: this.nextMaxId, }, }); this.state body; return body; }关键点端点路径为/api/v1/media/{mediaId}/comments/{commentId}/inline_child_comments/需要同时提供帖子媒体 IDmediaId与顶层评论 IDcommentId查询参数min_id/max_id是双向分页游标max_id从响应根对象的next_max_child_cursor获得用于向后翻页min_id用于向前翻页首次调用时由mediaInlineChildComments(mediaId, commentId, minId?)的第三个可选参数注入网络层通过this.client.request.send()发送请求构造见 src/core/request.ts其响应解析使用json-bigint将超长数字转为字符串见 request.ts这也是pk、parent_comment_id被声明为string的底层原因——Instagram 的评论 ID 常常超过 JavaScriptNumber.MAX_SAFE_INTEGER。4.2 分页状态机Feed 基类通过moreAvailable标志驱动循环翻页set state(state: MediaInlineChildCommentsFeedResponseRootObject) { this.moreAvailable !!state.next_max_child_cursor; this.nextMaxId state.next_max_child_cursor; this.nextMinId undefined; }每次request()都会把响应写回state更新moreAvailable与游标基类isMoreAvailable()feed.ts据此决定是否继续请求下一页。items()则直接返回req.child_comments即本接口所对应的对象数组public async items(): PromiseMediaInlineChildCommentsFeedResponseChildCommentsItem[] { const req await this.request(); return req.child_comments; }4.3 与媒体评论 Feed 的分工注意区分MediaInlineChildCommentsFeed与 src/feeds/media-comments.feed.ts 中的MediaCommentsFeedMediaCommentsFeed拉取顶层评论列表端点/api/v1/media/{id}/comments/携带can_support_threading: true其响应条目MediaCommentsFeedResponseCommentsItem中会附带child_comment_count、preview_child_comments、has_more_tail_child_comments、next_min_child_cursor等字段见 src/responses/media-comments.feed.response.ts用于提示“该评论下有多少回复”当需要真正展开某条评论的全部回复时再调用MediaInlineChildCommentsFeed按commentId精确拉取。两者构成“先取列表、再按需展开”的两级评论消费链路。五、实战用法遍历某条评论的全部子评论MediaInlineChildCommentsFeed通过 FeedFactory.mediaInlineChildComments() 暴露给上层方法签名为mediaInlineChildComments(mediaId: string, commentId: string, minId?: string)。完整调用链为IgApiClient.feed.mediaInlineChildComments(...)。结合 examples/session.example.ts 展示的会话初始化方式一个典型的子评论遍历脚本如下import { IgApiClient } from instagram-private-api; (async () { const ig new IgApiClient(); ig.state.generateDevice(process.env.IG_USERNAME); // 生产环境建议按 session.example.ts 的方式持久化并恢复会话状态 await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD); const mediaId 1234567890123456789; // 目标帖子的 media ID const commentId 17845678901234567; // 目标顶层评论的 pkstring // ① 手动分页逐页取 child_comments const feed ig.feed.mediaInlineChildComments(mediaId, commentId); do { const page: MediaInlineChildCommentsFeedResponseChildCommentsItem[] await feed.items(); for (const child of page) { console.log( [${child.user.username}] ${child.text} (likes: ${child.comment_like_count}, parent: ${child.parent_comment_id}), ); } } while (feed.isMoreAvailable()); // ② 或使用基类提供的 RxJS 流式迭代自动处理 400/429/500/502 限流重试 const feed2 ig.feed.mediaInlineChildComments(mediaId, commentId); feed2.items$.subscribe({ next: (items) console.log(page with ${items.length} child comments), error: (err) console.error(fetch failed, err), }); })().catch(console.error);关于上述代码的几点说明feed.items()每调用一次即发起一次网络请求并推进分页游标feed.isMoreAvailable()在游标耗尽后返回false。基类的items$属性feed.ts返回 RxJS Observable内部对400 / 429 / 500 / 502等 Instagram 限流/临时错误按指数退避自动重试默认maxAttempts: 10、初始延迟 60 秒见 feed.ts适合长时间大规模抓取场景。每一条child均为MediaInlineChildCommentsFeedResponseChildCommentsItem实例可放心访问上文列出的 15 个字段。六、使用提示与限制ID 一律按字符串处理由于请求层使用json-bigint把超长数字序列化为字符串pk、user_id、parent_comment_id等字段在 TypeScript 类型中分别声明为string/number读取与回传时应遵循接口声明的类型避免精度丢失。分页游标驱动判断“是否还有下一页”应依赖根对象的next_max_child_cursor经 Feed 内部转化为moreAvailable而非仅靠child_comments数组长度判断。字段可能缺省user.profile_pic_id声明为可选字段profile_pic_id?: string实际响应中可能缺失同时MediaCommentsFeedResponseCommentsItem中的has_more_tail_child_comments、next_min_child_cursor、num_head_child_comments等字段同样标记为可选访问时建议做防御性判断。请求频率Instagram 对评论类端点有严格的频率限制批量遍历时务必利用items$自带的重试与退避策略或自行控制调用节奏否则容易触发IgResponseError400/429。结语MediaInlineChildCommentsFeedResponseChildCommentsItem是 instagram-private-api 描述评论楼中楼回复的标准数据单元。通过本文的字段逐项解读与 Feed 实现 源码级分析你现在可以准确解析子评论的全部 15 个字段理解它与 父评论、根对象、用户 三类接口的关系并借助ig.feed.mediaInlineChildComments()完成从单页拉取到全量分页遍历的完整流程。相关类型声明与 Feed 定义均可从 responses 模块文档 与 feeds 模块文档 继续深入查阅。赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐OpenCADStudio命令行与脚本自动化完整指南如何用别名和命令脚本批量完成绘图任务OpenCADStudio命令行与脚本自动化完整指南如何用别名和命令脚本批量完成绘图任务 OpenCADStudio 是一款用 Rust 打造的开源 CAD后端instagram-private-api 数据响应结构详解StorySliderVotersFeedResponseResponseRootObject 接口深度解析instagram private api 数据响应结构详解StorySliderVotersFeedResponseResponseRootObject 接后端PX4-Autopilot 的 VehicleControlMode uORB 消息详解控制器调度总开关与飞行模式映射原理PX4 Autopilot 的 VehicleControlMode uORB 消息详解控制器调度总开关与飞行模式映射原理 本文以 PX4 Autopilot后端上一篇3步轻松获取A股数据Python通达信接口的终极解决方案下一篇airi 项目中 refDebounced 的深度解析为 Vue Ref 值构建防抖响应的实战指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
阅读完成 · 觉得有帮助?
咨询建站