
后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载本篇技术指南以 instagram-private-api 仓库中docs/interfaces/responses/DirectRepositoryCreateGroupThreadResponseUsersItem.md为骨架系统讲解通过ig.direct.createGroupThread()创建 Instagram 群聊会话Direct Thread后服务端返回的**用户条目UsersItem**数据结构的全部字段语义、嵌套类型与实战用法。读完本文你将能够直接解析创建群聊的响应对象、按字段筛选群成员信息并在 TypeScript 中安全地消费这类强类型响应。接口在仓库中的定位与调用背景在开始逐字段分析之前先明确该接口在项目中的上下文它并非独立存在的类型而是DirectRepository.createGroupThread()返回的根响应对象中users数组的元素类型。createGroupThread是 src/repositories/direct.repository.ts 中定义的低层仓库方法向 Instagram 私有接口POST /api/v1/direct_v2/create_group_thread/发送签名表单请求public async createGroupThread( recipientUsers: string[], threadTitle: string, ): PromiseDirectRepositoryCreateGroupThreadResponseRootObject { const { body } await this.client.request.send({ url: /api/v1/direct_v2/create_group_thread/, method: POST, form: this.client.request.sign({ _csrftoken: this.client.state.cookieCsrfToken, _uuid: this.client.state.uuid, _uid: this.client.state.cookieUserId, recipient_users: JSON.stringify(recipientUsers), thread_title: threadTitle, }), }); return body; }调用时传入两个参数recipientUsers接收者用户 ID 字符串数组与threadTitle群聊标题返回的body即DirectRepositoryCreateGroupThreadResponseRootObject。在该根对象中users字段的类型正是DirectRepositoryCreateGroupThreadResponseUsersItem[]见 源码也就是说每个成功加入群聊的成员都会以本文讲解的接口形态出现在响应里。接口定义位置与完整类型结构本接口的 TypeScript 定义位于 src/responses/direct.repository.create-group-thread.response.ts其完整结构如下export interface DirectRepositoryCreateGroupThreadResponseUsersItem { pk: number; username: string; full_name: string; is_private: boolean; profile_pic_url: string; profile_pic_id: string; friendship_status: DirectRepositoryCreateGroupThreadResponseFriendshipStatus; is_verified: boolean; has_anonymous_profile_picture: boolean; is_directapp_installed: boolean; is_using_unified_inbox_for_direct: boolean; }整个响应文件src/responses/direct.repository.create-group-thread.response.ts共声明了四个相互关联的接口接口名职责DirectRepositoryCreateGroupThreadResponseRootObject创建群聊的根响应包含users、inviter、thread_id等 33 个字段DirectRepositoryCreateGroupThreadResponseUsersItem本文主题根响应中users数组的元素DirectRepositoryCreateGroupThreadResponseFriendshipStatususers条目中嵌套的双方关系状态DirectRepositoryCreateGroupThreadResponseInviter创建群聊的发起者信息该接口在仓库的类型总览中登记于 docs/modules/responses.mdInterfaces 列表由 TypeDoc 从源码自动生成 API 文档因此文档与源码一一对应、字段完全一致。字段语义逐一详解DirectRepositoryCreateGroupThreadResponseUsersItem共声明 11 个属性可分为四类身份标识、个人资料、账号状态与关系状态。下面按源码声明顺序逐一说明。身份标识字段字段类型说明pknumberInstagram 用户的数字主键user id全库通用的用户唯一标识。可用于后续ig.user.info(pk)、ig.feed.user(pk)等一切以用户为主键的调用usernamestring用户的登录用户名如instagram.official不含前缀pk是整个响应中最常被提取的字段因为它是与仓库中绝大多数用户级 APIAccountRepository、UserRepository、FriendshipRepository等对接的桥梁。个人资料字段字段类型说明full_namestring用户显示的全名可为空字符串它独立于username是资料页展示用的昵称profile_pic_urlstring用户头像的 CDN 图片 URL可直接用于下载或展示profile_pic_idstring头像媒体的唯一标识media id。注意它与profile_pic_url是独立的两个字段有些接口返回中该字段可能缺失或为空账号状态字段字段类型说明is_privateboolean账号是否为私密账号private account。私密账号无法直接查看其帖子与粉丝is_verifiedboolean是否通过官方认证蓝色徽章。可用于群成员列表中对认证账号做特殊展示has_anonymous_profile_pictureboolean是否仍在使用系统默认头像匿名头像。结合profile_pic_url可判断用户是否主动设置过头像is_directapp_installedboolean该用户设备上是否安装了独立的 Direct 应用Instagram 曾独立上架的私信应用。对判断消息送达形态有一定参考意义is_using_unified_inbox_for_directboolean该用户是否使用「统一收件箱」接收私信。true表示其私信与普通消息在同一个收件箱中展示关系状态字段字段类型说明friendship_statusDirectRepositoryCreateGroupThreadResponseFriendshipStatus当前登录账号与该用户之间的双向关系状态为嵌套对象详细结构见下一节嵌套结构friendship_status 子接口friendship_status的类型不是布尔值或字符串而是完整的关系状态对象定义于同一响应文件的 第 51-59 行export interface DirectRepositoryCreateGroupThreadResponseFriendshipStatus { following: boolean; blocking: boolean; is_private: boolean; incoming_request: boolean; outgoing_request: boolean; is_bestie: boolean; is_restricted: boolean; }各字段含义如下字段类型业务含义followingboolean当前登录账号是否已关注该成员blockingboolean当前账号是否已拉黑该成员is_privateboolean该成员是否为私密账号与顶层is_private冗余但含义一致incoming_requestboolean该成员是否向当前账号发来过关注请求outgoing_requestboolean当前账号是否已向该成员发出待处理关注请求is_bestieboolean该成员是否处于当前账号的「密友Besties」列表中is_restrictedboolean该成员是否被当前账号「限制Restricted」这些字段组合起来可以直接支撑群成员亲疏程度的判定逻辑例如following is_bestie为true时可以认为该成员与登录账号关系紧密blocking为true时则应在 UI 中做特殊处理。在根响应对象中的位置与数据流users数组只是根响应 33 个字段之一。完整的根对象结构定义于 src/responses/direct.repository.create-group-thread.response.ts其 TypeDoc 页面为 docs/interfaces/responses/DirectRepositoryCreateGroupThreadResponseRootObject.md。与群成员直接相关的关键字段包括thread_id/thread_v2_id新建群聊的线程 ID两代版本后续向该群发消息需用到users群成员列表元素即本文讲解的接口left_users已离开的成员列表admin_user_ids管理员用户 ID 数组number[]可用来与users[i].pk交叉比对判断谁是管理员inviter发起建群者的资料DirectRepositoryCreateGroupThreadResponseInviteris_group、named、thread_title群聊属性是否为群、是否有名称、群标题approval_required_for_new_members新成员是否需要审批。典型的数据流是createGroupThread(recipientUsers, threadTitle)返回根对象 → 通过users拿到成员列表 → 用user.pk、user.username、user.friendship_status等字段完成群成员信息的渲染、筛选或后续 API 调用。实战示例解析并消费群成员数据结合 examples 目录的工程风格先ig.state.generateDevice()再ig.account.login()一个完整的消费示例import { IgApiClient } from instagram-private-api; const ig new IgApiClient(); ig.state.generateDevice(process.env.IG_USERNAME); // 可选ig.state.proxyUrl process.env.IG_PROXY; async function main() { await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD); const recipientUsers [user_pk_1, user_pk_2, user_pk_3]; const thread await ig.direct.createGroupThread(recipientUsers, 项目讨论群); // thread.users 的元素类型即 DirectRepositoryCreateGroupThreadResponseUsersItem for (const user of thread.users) { console.log({ pk: user.pk, username: user.username, full_name: user.full_name, is_private: user.is_private, is_verified: user.is_verified, following: user.friendship_status.following, is_bestie: user.friendship_status.is_bestie, avatar: user.profile_pic_url, }); } // 用 admin_user_ids 与 users 交叉比对找出群管理员 const admins thread.users.filter((u) thread.admin_user_ids.includes(u.pk)); console.log(admins:, admins.map((u) u.username)); // 拿到 thread_id 后即可通过 DirectThreadEntity 在群内发消息 return thread.thread_id; } main();注意ig.direct即DirectRepository在IgApiClient上的实例命名遵循 README 中去掉Repository后缀、转为 camelCase的约定详见 README 的 Repositories 章节。创建成功后的群聊线程还可以通过 src/entities/direct-thread.entity.ts 的DirectThreadEntity继续执行broadcastText、broadcastPhoto、addUser、updateTitle等操作实现完整的群聊自动化流程。类型安全与使用注意事项字段可能缺失DirectRepositoryCreateGroupThreadResponseUsersItem是全必填的严格接口但 Instagram 服务端在不同网络或账号场景下可能返回缺字段的 JSON。若对接不稳定建议在消费前用profile_pic_id in user或可选链做防御性判断。pk精度问题Instagram 的用户pk数值很大TypeScript 的number类型在严格场景下可能损失精度若需把pk序列化到字符串键或与字符串 ID 混用建议先String(pk)转换。响应类型仅用于解析本接口及同类*Response*接口完整清单见 docs/modules/responses.md仅用于标注响应体结构不应作为请求表单类型使用请求侧参数应使用 src/types 目录下的*Options类型。低层方法 vs 高层实体createGroupThread是一次请求一个响应的低层仓库方法仓库方法遵循每次方法恰好发送一个 API 请求的约定若要做建群 发首条消息的组合操作可结合DirectThreadEntity或SimulateService高层服务编排见 docs/modules/services.md。小结DirectRepositoryCreateGroupThreadResponseUsersItem是 instagram-private-api 创建群聊场景下描述单个群成员的标准类型顶层承载用户身份、资料与账号状态嵌套的friendship_status则补充双向关系细节。理解它的字段语义配合 src/repositories/direct.repository.ts 的请求入口与根对象结构即可在 TypeScript 项目中安全地完成建群、成员筛选、管理员识别与后续群聊消息发送的完整开发闭环。赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐instagram-private-api 群聊创建响应结构解析DirectRepositoryCreateGroupThreadResponseRootObject 接口全字段指南instagram private api 群聊创建响应结构解析DirectRepositoryCreateGroupThreadResponseRootOb后端RocksDB BitFields API面向无锁数据结构的类型安全位打包方案RocksDB BitFields API面向无锁数据结构的类型安全位打包方案 本篇技术指南深入讲解 RocksDB 中可复用的 BitFields API后端instagram-private-api 登录响应全解析AccountRepositoryLoginResponseLogged_in_user 接口字段详解与源码验证instagram private api 登录响应全解析AccountRepositoryLoginResponseLogged_in_user 接口字段详后端上一篇深入浅出 NYU-DLSP20 优化方法二自适应学习率、归一化层与优化的终结——从 RMSprop/ADAM 到加速 MRI 重建实战下一篇Sharp-dumpkey 1分钟快速提取微信数据库AES密钥解锁你的本地聊天记录创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考