后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载导读本文聚焦instagram-private-apiNodeJS 编写的 TypeScript 版 Instagram 私有 API SDK中设置亲密好友Besties / 挚友功能的核心响应数据结构FriendshipRepositorySetBestiesResponseRootObject。你将理解该接口在 SDK 中的定位、其两个字段friendship_statuses与status的精确类型定义与语义、底层请求的构造方式以及如何在实际代码中调用ig.friendship.setBesties()并解析返回值用于批量管理账号的亲密好友关系。一、接口在 SDK 中的位置FriendshipRepositorySetBestiesResponseRootObject属于 SDK 的responses 模块在文档体系中挂在docs/interfaces/responses/目录下并在 responses 模块索引 中对外暴露。它描述的是 Instagram 私密接口POST /api/v1/friendships/set_besties/返回的根对象结构。该响应由FriendshipRepository.setBesties()方法使用方法签名定义在 FriendshipRepository 类文档 中setBesties(input?: SetBestiesInput): PromiseRecordstring, FriendshipRepositorySetBestiesResponseRootObject_status注意setBesties方法返回时已经解包了响应根对象直接返回内部的friendship_statuses映射Recordstring, ...也就是说方法层面的返回类型比网络响应少了一层。因此FriendshipRepositorySetBestiesResponseRootObject主要在底层类型契约层面发挥作用——它约束了仓库层request.send...泛型参数所对应的真实 HTTP 响应体。二、根对象接口字段详解该接口共两个属性定义于 src/responses/friendship.repository.besties.response.tsexport interface FriendshipRepositorySetBestiesResponseRootObject { friendship_statuses: Recordstring, FriendshipRepositorySetBestiesResponseRootObject_status; status: string; }字段类型说明friendship_statusesRecordstring, FriendshipRepositorySetBestiesResponseRootObject_status以用户 PK数字 ID 的字符串形式为键、以单用户亲密状态为值的映射表覆盖本次操作涉及的所有目标用户statusstringInstagram API 通用的响应状态标识正常时值为okfriendship_statuses批量结果的载体之所以是Recordstring, ...而非数组是因为一次set_besties请求可以同时传入add与remove两组用户列表见下文 SetBestiesInput服务端需要为每一个受影响的用户分别回传一份最新的关系快照。使用用户 PK 作为映射键调用方可以 O(1) 地按 ID 精确查询某个用户的亲密状态是否已成功变更无需遍历数组。这与单用户操作接口如show、create返回单个friendship_status对象的模式形成鲜明对比——例如 FriendshipRepositoryChangeResponseRootObject 中字段名为单数friendship_status而本接口是复数friendship_statuses。三、子对象 FriendshipRepositorySetBestiesResponseRootObject_status 逐字段解析映射的每个值是一个FriendshipRepositorySetBestiesResponseRootObject_status它刻画了某个用户与当前登录账号之间完整的关注关系状态字段定义于 src/responses/friendship.repository.besties.response.ts同时有独立的接口文档 FriendshipRepositorySetBestiesResponseRootObject_statusexport interface FriendshipRepositorySetBestiesResponseRootObject_status { following: boolean; followed_by: boolean; blocking: boolean; muting: boolean; is_private: boolean; incoming_request: boolean; outgoing_request: boolean; is_bestie: boolean; }字段类型语义followingboolean当前登录账号是否已关注该用户followed_byboolean该用户是否已关注当前登录账号blockingboolean当前登录账号是否已拉黑该用户mutingboolean当前登录账号是否已屏蔽静音该用户的帖文或动态is_privateboolean该用户账号是否为私密账号private accountincoming_requestboolean是否存在来自该用户的关注请求对方请求关注我们outgoing_requestboolean是否存在发往该用户的关注请求我们请求关注对方is_bestieboolean该用户是否为当前登录账号的亲密好友——本操作的核心结果字段is_bestie 是关键判别字段设置成功后目标用户的is_bestie应为true如果同时执行了移除操作被移除用户的is_bestie则应为false。因此在编程实践中正确解读friendship_statuses的方式是// 假设我们添加了两个用户并移除了一个用户 const statuses await ig.friendship.setBesties({ add: [userIdA, userIdB], remove: [userIdC], }); for (const [pk, friendship] of Object.entries(statuses)) { console.log(用户 ${pk} 的最新关系快照); console.log( is_bestie: ${friendship.is_bestie}); console.log( following: ${friendship.following}, followed_by: ${friendship.followed_by}); console.log( is_private: ${friendship.is_private}, muting: ${friendship.muting}); }与其他响应结构的关联这个子对象结构与 SDK 中其他多处出现的friendship_status结构高度一致例如FriendshipRepositoryChangeResponseFriendship_statusblock/unblock/create/destroy等变更操作的返回FriendshipRepositoryShowResponseRootObject单用户关系查询额外多出is_blocking_reel、is_muting_reel两个字段BestiesFeedResponseUsersItemBesties 列表流中的用户项。它们都包含is_bestie说明is_bestie是整个 SDK 中贯穿“亲密好友”这一概念的统一状态标志无论你通过 set 接口写入、通过 show 接口查询还是通过 Besties 列表读取都能用同一个字段判断亲密关系。从源码结构看这些相似结构是 SDK 为不同 endpoint 分别建模的产物尚未统一抽取为单一公共类型。四、底层调用链setBesties 方法如何产生该响应FriendshipRepository.setBesties()的实现位于 src/repositories/friendship.repository.ts是唯一产生FriendshipRepositorySetBestiesResponseRootObject响应的入口async setBesties(input: SetBestiesInput {}) { const { body } await this.client.request.sendFriendshipRepositorySetBestiesResponseRootObject({ url: /api/v1/friendships/set_besties/, method: POST, form: this.client.request.sign({ _csrftoken: this.client.state.cookieCsrfToken, _uid: this.client.state.cookieUserId, device_id: this.client.state.deviceId, _uuid: this.client.state.uuid, module: favorites_home_list, source: audience_manager, add: input.add, remove: input.remove, }), }); return body.friendship_statuses; }调用链可概括为组装表单除业务参数add/remove外还会附加_csrftoken、_uid、device_id、_uuid等会话标识以及module: favorites_home_list与source: audience_manager两个用于模拟客户端来源的字段签名通过this.client.request.sign(...)进行端点签名Instagram 私有端口的签名要求随后以表单form形式 POST类型约束request.sendFriendshipRepositorySetBestiesResponseRootObject用该接口约束响应体类型保证body.friendship_statuses与body.status的静态类型安全解包返回方法最终返回body.friendship_statuses把Recordstring, FriendshipRepositorySetBestiesResponseRootObject_status直接暴露给调用方与上面文档中setBesties的PromiseRecord...返回类型完全对应。输入类型 SetBestiesInput入参input的类型定义于 src/types/set-besties.input.ts并在 types 模块索引 中导出export type SetBestiesInput { add?: Arraystring | number; remove?: Arraystring | number; };参数类型说明add?Arraystring \| number要添加为亲密好友的用户 PK 列表可为空表示本次只做移除remove?Arraystring \| number要移除亲密好友关系的用户 PK 列表可为空表示本次只做添加两者均为可选且可同时传入因此一次调用即可完成“增删”的批量操作。需要注意set_besties的添加方向通常是单向的“你将对方标为亲密”最终以响应中的is_bestie为权威结果。五、实战示例完整使用流程结合 session.example.ts 中的会话建立模式一个完整的调用示例如下import { IgApiClient } from ./src; (async () { const ig new IgApiClient(); ig.state.generateDevice(你的用户名); await ig.account.login(你的用户名, 你的密码); // 批量设置亲密好友添加两个用户同时移除一个用户 const statuses await ig.friendship.setBesties({ add: [1234567890, 2234567891], remove: [3234567892], }); console.log(接口 status:, statuses); // 注意方法已解包这里即 friendship_statuses // 验证每个目标用户的新关系状态 for (const [pk, s] of Object.entries(statuses)) { console.log(用户 ${pk}: is_bestie${s.is_bestie}, following${s.following}, followed_by${s.followed_by}); } // 若只做添加可不传 remove若只做移除可不传 add const onlyAdd await ig.friendship.setBesties({ add: [2234567891] }); const onlyRemove await ig.friendship.setBesties({ remove: [1234567890] }); })();验证亲密好友结果使用 Besties 列表流设置之后可以通过BestiesFeed读取当前的亲密好友列表进行交叉验证。该 Feed 定义于 src/feeds/account-friendships-besties.feed.ts请求GET /api/v1/friendships/besties返回BestiesFeedResponseUsersItem[]其中每个用户项同样携带is_bestie与friendship_status字段见 account-friendships-besties.feed.response.tsconst bestiesFeed ig.feed.besties(); const besties await bestiesFeed.items(); for (const user of besties) { console.log(${user.username} (pk${user.pk}) is_bestie${user.is_bestie}); }六、最佳实践与注意事项使用解包后的返回值setBesties()直接返回friendship_statuses映射无需再从根对象中手动取字段但如果你在仓库层或其他场景需要完整的根对象含status字段以校验ok则需自行构造与 friendship.repository.besties.response.ts 一致的结构来承接原始响应。批量优于单次与逐用户调用关注/取关接口不同set_besties天然支持批量应在程序设计中尽量一次提交多个 PK减少请求次数、降低触发风控的概率。以服务端返回为准是否真正生效应以响应中各用户的is_bestie为准由于涉及账号风控、网络波动等情况若某项未按预期生效可通过 FriendshipRepository.show() 单独复查该用户关系。控制操作频率频繁大批量变更亲密关系可能触发 Instagram 的限制SDK 亦内置了如 IgActionSpamError 等错误类型建议分批执行并加入适当延时。类型安全收益由于响应类型是显式接口配合 TypeScript 严格模式可在编译期发现字段名拼写错误例如把friendship_statuses误写为friendship_status这是 SDK 将响应结构建模为独立接口文件src/responses/*.response.ts的核心价值。七、总结FriendshipRepositorySetBestiesResponseRootObject是instagram-private-api中亲密好友批量管理功能的类型基石根对象通过friendship_statuses: Recordstring, FriendshipRepositorySetBestiesResponseRootObject_status承载多用户关系快照子对象以 8 个布尔字段完整刻画每个目标用户的关注、拉黑、静音、私密与亲密状态。配合 FriendshipRepository.setBesties() 与 SetBestiesInput 输入类型开发者可以在一次请求内完成批量添加/移除亲密好友并通过is_bestie字段精确校验操作结果。若需进一步阅读可查看 FriendshipRepository 类完整文档、responses 模块索引 以及源码目录 src/responses深入理解 SDK 的响应建模与仓库调用设计。赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐instagram-private-api 亲密好友Besties响应接口 BestiesFeedResponse 全解析instagram private api 亲密好友Besties响应接口 BestiesFeedResponse 全解析 本文基于 instagram p后端Artillery 自定义指标跟踪实战用 afterResponse 处理器统计请求计数与延迟直方图Artillery 自定义指标跟踪实战用 afterResponse 处理器统计请求计数与延迟直方图 Artillery 内置的 HTTP 引擎在每次请求后都后端instagram-private-api 响应结构解析DirectThreadRepositoryGetByParticipantsResponseFriendshipStatus 接口详解instagram private api 响应结构解析DirectThreadRepositoryGetByParticipantsResponseFrie后端上一篇Seed-VC零样本语音转换技术深度解析扩散变换器架构与实时性能优化下一篇解决表单验证痛点Zod异步验证完全指南创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考