- 后端
【免费下载链接】instagram-private-api
NodeJS Instagram private API SDK. Written in TypeScript.
本指南围绕 instagram-private-api(NodeJS Instagram 私有 API SDK,TypeScript 编写)中LikedFeedResponseFriendship_status接口展开,介绍它在「我点赞过的帖子」动态流(Liked Feed)响应中所承载的用户关系状态字段、各字段的业务含义,以及如何在LikedFeed分页拉取场景下基于这些状态做关注判断、亲密好友筛选等实战处理。读完本文,你将掌握该接口的全部四个布尔字段、其来源接口层级与底层 API 调用链,并能结合 FriendshipRepository 与ProfileEntity编写可运行的关系状态判定代码。
一、接口概览:点赞流里的关系快照
LikedFeedResponseFriendship_status是 instagram-private-api 为「我点赞过的帖子」接口生成的响应类型之一,定义在 src/responses/liked.feed.response.ts。它不属于根对象,而是嵌套在媒体条目(LikedFeedResponseItemsItem)的作者信息(LikedFeedResponseUser)之下,以可选属性friendship_status的形式出现。
整个类型链从 TypeDoc 生成的结构看是:
- LikedFeedResponseRootObject →
items: LikedFeedResponseItemsItem[] - LikedFeedResponseItemsItem →
user: LikedFeedResponseUser - LikedFeedResponseUser →
friendship_status?: LikedFeedResponseFriendship_status
也就是说,每一条你点赞过的媒体记录里,Instagram 服务端都可能顺带返回一个关于该媒体作者与你(当前登录账号)之间关系状态的迷你快照,接口源码中对应的声明为:
export interface LikedFeedResponseFriendship_status { following: boolean; outgoing_request: boolean; is_bestie: boolean; is_restricted: boolean; }接口原文定义见 docs/interfaces/responses/LikedFeedResponseFriendship_status.md,四个属性全部为boolean,没有任何可选字段。
二、四个布尔字段逐一解读
1.following:你是否已关注该作者
- 类型:
boolean - 含义:当前登录账号是否已经关注该媒体作者。
- 典型场景:拉取点赞流后,用它过滤「我点赞了但还没关注」的作者,作为批量关注、私信触达前的去重判断。
2.outgoing_request:是否存在待处理的主动关注请求
- 类型:
boolean - 含义:你对该作者是否发出了关注请求但尚未被对方接受(通常对应对方是私密账号的场景)。
- 注意点:
outgoing_request与following是相互独立又互斥的状态——following: true表示已建立关注关系;outgoing_request: true表示请求仍在途,尚未建立关注关系。两个都为false则说明当前无关注关系。
3.is_bestie:对方是否在你的「亲密好友」列表中
- 类型:
boolean - 含义:该作者是否被设置为你的 Besties(亲密好友)。
- 典型场景:结合 FriendshipRepository.setBesties 与 SetBestiesInput(
{ add?: Array<string | number>; remove?: Array<string | number> }),可以批量维护亲密好友名单,并在点赞流中校验维护结果是否生效。
4.is_restricted:对方是否处于受限(restrict)状态
- 类型:
boolean - 含义:该作者是否被 Instagram 标记为受限账号,或者你是否对其启用了「受限」交互设置。受限状态通常意味着评论、私信等互动会被过滤或降权。
- 使用建议:在粉丝运营、评论分析场景中,优先排除
is_restricted: true的用户,避免互动数据失真。
三、它在响应层级中的位置:为什么是可选的
在 src/responses/liked.feed.response.ts 中,LikedFeedResponseUser将其声明为可选:
export interface LikedFeedResponseUser { pk: number; username: string; full_name: string; is_private: boolean; profile_pic_url: string; friendship_status?: LikedFeedResponseFriendship_status; is_verified: boolean; has_anonymous_profile_picture?: boolean; is_unpublished?: boolean; is_favorite?: boolean; can_see_primary_country_in_settings?: boolean; latest_reel_media?: number; profile_pic_id?: string; }这意味着服务端并非对每条媒体都保证返回friendship_status。Instagram 的/api/v1/feed/liked/接口在批量返回媒体列表时,出于带宽与缓存考虑,可能省略部分作者的关系状态。因此编码时必须做空值防御:
const status = item.user?.friendship_status; if (status && status.following) { // 已关注的作者 }同类设计中,is_private、is_verified等核心字段是必填的,而friendship_status以及profile_pic_id、is_favorite等属于按需返回的附加信息。
四、底层调用链:LikedFeed 如何拉取这些数据
该接口的数据来自LikedFeed类发起的请求,实现在 src/feeds/liked.feed.ts:
async request(): Promise<LikedFeedResponseRootObject> { const { body } = await this.client.request.send({ url: `/api/v1/feed/liked/`, method: 'GET', qs: { max_id: this.maxId, }, }); this.state = body; return body; }关键调用链信息:
- 端点:
GET /api/v1/feed/liked/,返回「当前登录账号点赞过的媒体」列表; - 分页参数:
max_id,由响应中的next_max_id回填;LikedFeed的set state()同时维护moreAvailable与maxId(src/feeds/liked.feed.ts),驱动分页循环; - 根对象结构:LikedFeedResponseRootObject 包含
items、num_results、more_available、auto_load_more_enabled、next_max_id、status。
LikedFeed继承自通用 Feed 基类(src/core/feed.ts),因此天然支持items()、isMoreAvailable()、items$(RxJS Observable 流)以及serialize()/deserialize()等分页与状态持久化能力。
五、同类关系状态接口对比
LikedFeedResponseFriendship_status并非仓库中唯一的关系状态类型,理解它与兄弟接口的差异有助于避免误用:
| 接口 | 字段 | 出现场景 |
|---|---|---|
LikedFeedResponseFriendship_status(本文) | following、outgoing_request、is_bestie、is_restricted | 点赞流媒体作者的内嵌关系快照(可选) |
| FriendshipRepositoryShowResponseRootObject | following、followed_by、blocking、muting、is_private、incoming_request、outgoing_request、is_blocking_reel、is_muting_reel、is_bestie | 通过GET /api/v1/friendships/show/{id}/获取的单用户完整关系状态(src/repositories/friendship.repository.ts) |
| FriendshipRepositoryChangeResponseFriendship_status | following、followed_by、blocking、muting、is_private、incoming_request、outgoing_request、is_bestie | 关注/取关/拉黑等操作后返回的关系状态(src/repositories/friendship.repository.ts) |
可以看出:点赞流内嵌的关系快照字段最少,只覆盖最常用的四个布尔状态;需要完整关系信息(如incoming_request、blocking)时,应改用client.friendship.show(pk)单独查询。这也是为什么LikedFeedResponseFriendship_status只用于批量浏览时的轻量判断,不适合作为关系状态的权威来源。
六、实战:基于点赞流做关系状态分析
场景 A:遍历点赞流并统计未关注作者
import { IgApiClient } from './src/index'; (async () => { const ig = new IgApiClient(); ig.state.generateDevice('your_username'); await ig.account.login('your_username', 'your_password'); const likedFeed = ig.feed.liked(); const unFollowedAuthors: Array<{ pk: number; username: string }> = []; const besties: Array<{ pk: number; username: string }> = []; do { const items = await likedFeed.items(); for (const item of items) { const user = item.user; const status = user?.friendship_status; if (!status) continue; // 服务端未返回关系快照,跳过 if (!status.following && !status.outgoing_request) { unFollowedAuthors.push({ pk: user.pk, username: user.username }); } if (status.is_bestie) { besties.push({ pk: user.pk, username: user.username }); } } } while (likedFeed.isMoreAvailable()); console.log('未关注的点赞作者:', unFollowedAuthors); console.log('亲密好友作者:', besties); })();提示:点赞流接口的调用频率受限于登录状态与请求频率策略,实际批量拉取时建议控制分页轮数,并参考仓库中的 session.example.ts 做好会话状态持久化,避免频繁登录触发风控。
场景 B:对未关注作者执行关注操作(幂等写法)
仓库在 ProfileEntity 中提供了关注/取关的幂等封装checkFollow()与checkUnfollow(),其内部正是调用friendship.show()校验following后再执行create()/destroy():
// checkFollow 的实现逻辑(src/entities/profile.entity.ts) const friendshipStatus = await this.client.friendship.show(this.pk); if (friendshipStatus.following === true) return friendshipStatus; return await this.client.friendship.create(this.pk);点赞流条目中的user属于普通对象而非实体类,如需复用上述幂等逻辑,可先构造ProfileEntity实例,或直接调用仓库方法:
import { ProfileEntity } from './src/entities/profile.entity'; const profile = new ProfileEntity(ig); profile.pk = item.user.pk; const status = await profile.checkFollow(); // 已关注则原样返回,否则发起关注 console.log('关注后状态 following =', status.following);场景 C:配合 Besties 管理校验
若你通过client.friendship.setBesties({ add: [pk] })添加了亲密好友,可以用点赞流中的is_bestie快速校验结果是否已生效(注意点赞流缓存可能导致延迟,权威校验仍以friendship.show()为准)。
七、易踩坑点小结
- 字段可选性:
friendship_status在LikedFeedResponseUser中是Optional,访问前务必判空; - 状态含义互斥:
following与outgoing_request不会同时为true,两者皆false才是真正无关系; - 轻量快照而非权威数据:需要
incoming_request、blocking、muting等字段时请改用 friendship.show; - 分页状态:
LikedFeed的state通过next_max_id与more_available维护游标,不要在循环内重新实例化 Feed; - 频率控制:点赞流批量拉取与批量关注属于高敏操作,建议结合请求重试与随机延时,参照 unfollow-users.example.ts 的批量处理思路。
八、扩展阅读
- 接口定义与全量响应模型:src/responses/liked.feed.response.ts(
LikedFeedResponseRootObject与LikedFeedResponseItemsItem均在 1–44 行); - 分页 Feed 实现:src/feeds/liked.feed.ts 与通用基类 src/core/feed.ts;
- 完整关系状态查询与变更:src/repositories/friendship.repository.ts 及 friendship.repository.show.response.ts;
- 登录与会话管理:examples/session.example.ts、examples/2fa-sms-login.example.ts。
通过本文,你已经清楚LikedFeedResponseFriendship_status的字段语义、在点赞流响应中的位置、底层 API 来源及其与FriendshipRepository的配合方式,可以在此基础上安全地构建关注策略、亲密好友分析与内容运营等上层能力。
- 后端
【免费下载链接】instagram-private-api
NodeJS Instagram private API SDK. Written in TypeScript.
相关推荐
instagram-private-api 中 IgtvSearchResponseFriendship_status 接口详解:解析 IGTV 搜索结果的用户关系状态
instagram private api 中 IgtvSearchResponseFriendship_status 接口详解:解析 IGTV 搜索结果的用户
后端instagram-private-api 接口解析:HighlightsRepositoryHighlightsTrayResponseFriendship_status 好友关系状态详解
instagram private api 接口解析:HighlightsRepositoryHighlightsTrayResponseFriendship_
后端instagram-private-api 中 ReelsTrayFeedResponseFriendship_status 接口详解:Reels 故事托盘响应里的用户关系状态结构
instagram private api 中 ReelsTrayFeedResponseFriendship_status 接口详解:Reels 故事托盘响应
后端
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考