资讯动态

instagram-private-api UsertagsFeedResponseItemsItem 接口详解:解码“我被标记“动态的完整字段结构

发布时间:2026/10/16 3:58:23 来源:尧图企业网站定制
后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载本文以 instagram-private-apiNodeJS Instagram 私有 API SDKTypeScript 编写中UsertagsFeedResponseItemsItem接口为核心结合其上游UsertagsFeed与底层响应定义 src/responses/usertags.feed.response.ts逐字段剖析用户被标记usertags动态流中每条媒体数据的完整结构涵盖图片候选、标签坐标、预览评论、位置信息等关键子结构并给出实际调用ig.feed.usertags()分页读取与序列化的可运行示例帮助你在会话存档、自动化打标回读与数据清洗等场景中直接落地。一、接口定位它描述了什么数据UsertagsFeedResponseItemsItem是 Instagram 私有端点GET /api/v1/usertags/{user_id}/feed/返回响应中items数组的单个元素类型即当前用户被他人标记photo of you动态流中的一条媒体图片/轮播/视频条目。其数据来源与调用链在仓库中清晰可见响应根对象接口定义于 src/responses/usertags.feed.response.ts#L1-L11其中items: UsertagsFeedResponseItemsItem[]即为本接口的数组容器分页逻辑实现在 src/feeds/usertags.feed.ts 的UsertagsFeed类中它继承自 src/core/feed.ts 的FeedUsertagsFeedResponseRootObject, UsertagsFeedResponseItemsItem泛型基类客户端入口由 src/core/feed.factory.ts#L206-L208 的FeedFactory.usertags(id: number | string)工厂方法提供并通过src/feeds/index.ts导出。也就是说拿到UsertagsFeedResponseItemsItem就等于拿到了一条我被标记媒体在 API 层的完整快照从图片 URL、作者信息到评论预览、标签坐标一应俱全。二、字段全景总览34 个属性根据 src/responses/usertags.feed.response.ts#L12-L47 的接口定义UsertagsFeedResponseItemsItem共声明 34 个属性可按职责划分为五大类分类字段类型说明媒体身份taken_atnumberUnix 时间戳秒拍摄/发布时刻pkstring媒体主键media pk字符串形式idstring媒体 ID形如pk_shortcode的组合标识codestring短码shortcode用于构造分享链接client_cache_keystring客户端缓存键用于本地去重/缓存device_timestampnumber设备端时间戳媒体内容media_typenumber媒体类型1图片2视频8轮播image_versions2UsertagsFeedResponseImage_versions2图片候选版本容器original_width/original_heightnumber原始图片宽高filter_typenumber滤镜类型标识作者与关系userUsertagsFeedResponseUser媒体作者含好友关系状态can_viewer_reshareboolean当前登录用户是否可以转发分享can_viewer_saveboolean当前登录用户是否可以保存该媒体photo_of_youboolean是否为包含你的照片评论与互动comment_countnumber评论总数preview_commentsUsertagsFeedResponsePreviewCommentsItem[]预览评论列表前几条max_num_visible_preview_commentsnumber可见预览评论的最大条数can_view_more_preview_commentsboolean是否可查看更多预览评论has_more_commentsboolean是否还有更多评论comment_likes_enabledboolean评论点赞功能是否开启comment_threading_enabledboolean评论楼中楼是否开启next_max_idstring评论分页游标inline_composer_display_conditionstring内联评论输入框显示条件inline_composer_imp_trigger_timenumber内联输入框曝光触发时间caption_is_editedboolean文案是否被编辑过captionUsertagsFeedResponseCaption文案对象含全文与作者like_countnumber点赞数has_likedboolean当前用户是否已点赞标签与位置usertagsUsertagsFeedResponseUsertags本媒体上的用户标签打标对象locationUsertagsFeedResponseLocation可选位置信息latnumber可选纬度lngstring可选经度注意根接口中为字符串类型追踪信息organic_tracking_tokenstring自然流量追踪令牌三、核心嵌套子结构逐个拆解3.1 图片候选image_versions2定义于 src/responses/usertags.feed.response.ts#L48-L56export interface UsertagsFeedResponseImage_versions2 { candidates: UsertagsFeedResponseCandidatesItem[]; } export interface UsertagsFeedResponseCandidatesItem { width: number; height: number; url: string; estimated_scans_sizes: number[]; }candidates是按分辨率提供的多个图片版本常见为缩略图、低清、高清等多档直接取candidates[0].url通常为最高可用版本即可获取图片直链。estimated_scans_sizes为渐进式加载的估算扫描尺寸数组用于客户端渐进渲染普通业务读取时可忽略。3.2 标签主体usertags→in[]→positionUsertagsFeedResponseItemsItem中的usertags字段本身是一个容器接口src/responses/usertags.feed.response.ts#L95-L97内部只有一个属性in其元素UsertagsFeedResponseInItem才是真正的某个人被标记在什么位置export interface UsertagsFeedResponseUsertags { in: UsertagsFeedResponseInItem[]; } export interface UsertagsFeedResponseInItem { user: UsertagsFeedResponseUser; position: number[] | (number | string)[]; start_time_in_video_in_sec: null; duration_in_video_in_sec: null; }关键字段说明user被标记的用户复用UsertagsFeedResponseUser结构见 3.3position归一化坐标对[x, y]01 区间表示标签锚点在媒体画面中的相对位置由于接口由 JSON 自动推导类型被推断为number[] | (number | string)[]实际为数值数组start_time_in_video_in_sec/duration_in_video_in_sec视频内标签的时间窗秒在此接口中固定为null——因为在被标记动态流里接口返回的标签不携带视频时间信息仅位置坐标。提示UsertagsFeedResponseInItem的position坐标是归一化的若要在原始像素坐标系中还原标签位置需乘以original_width/original_height进行换算。3.3 作者与标记人UsertagsFeedResponseUser定义于 src/responses/usertags.feed.response.ts#L57-L69是整棵数据树中被复用最多的子结构作者user、被标记人in[].user、评论人preview_comments[].user、文案作者caption.user均指向它export interface UsertagsFeedResponseUser { pk: number; username: string; full_name: string; is_private: boolean; profile_pic_url: string; profile_pic_id?: string; friendship_status?: UsertagsFeedResponseFriendship_status; is_verified: boolean; has_anonymous_profile_picture?: boolean; is_unpublished?: boolean; is_favorite?: boolean; }其中friendship_statussrc/responses/usertags.feed.response.ts#L70-L75包含following、outgoing_request、is_bestie、is_restricted四个布尔值可直接判断当前登录用户与该作者/被标记人的关系状态。3.4 预览评论preview_comments定义于 src/responses/usertags.feed.response.ts#L76-L94。每项为一条评论摘要包含pk、text、created_at/created_at_utc、user评论作者、comment_like_count、has_liked_comment、did_report_as_spam等字段parent_comment_id与has_translation为可选字段——前者出现在楼中楼回复场景后者出现在可翻译评论场景。next_max_id字段则用于通过 MediaCommentsFeed 继续拉取全部评论。3.5 文案与位置captionsrc/responses/usertags.feed.response.ts#L104-L119与预览评论结构高度相似额外提供完整text全文与user作者locationsrc/responses/usertags.feed.response.ts#L120-L129包含pk、name、address、city、short_name、lng、lat、external_source、facebook_places_id为可选字段未标注位置时缺失lat/lng均为可选字段且根接口中lng被推导为string而location.lng为number读取时建议做一次Number()归一化。四、如何拿到这一结构UsertagsFeed 与分页机制UsertagsFeedResponseItemsItem的实例化完全依赖UsertagsFeed的分页迭代。看 src/feeds/usertags.feed.ts 的实现export class UsertagsFeed extends FeedUsertagsFeedResponseRootObject, UsertagsFeedResponseItemsItem { id: number | string; Expose() private nextMaxId: string; protected set state(body: UsertagsFeedResponseRootObject) { this.moreAvailable body.more_available; this.nextMaxId body.next_max_id; } async request() { const { body } await this.client.request.sendUsertagsFeedResponseRootObject({ url: /api/v1/usertags/${this.id}/feed/, qs: { max_id: this.nextMaxId }, }); this.state body; return body; } async items() { const body await this.request(); return body.items; } }从实现可提炼出三个关键机制端点与游标请求发往/api/v1/usertags/{id}/feed/携带max_id查询参数。响应体中的next_max_idsrc/responses/usertags.feed.response.ts#L6被写入nextMaxId作为下一页游标more_availablesrc/responses/usertags.feed.response.ts#L4被写入moreAvailable作为是否有下一页的标志。分页状态机基类Feed的isMoreAvailable()src/core/feed.ts#L87-L89读取moreAvailable因此items()只需顺序调用即可逐页翻取每次返回一页UsertagsFeedResponseItemsItem[]。会话持久化基类提供的serialize()/deserialize()src/core/feed.ts#L75-L81基于class-transformer的Expose()注解仅导出nextMaxId等游标字段可将翻页进度保存/恢复实现断点续读。实际调用示例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 () { await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD); // 通过 FeedFactory 创建 UsertagsFeed需传入目标用户 pk const usertagsFeed ig.feed.usertags(ig.state.account!.pk); // 顺序调用 items() 即可自动分页翻取每次返回一页 UsertagsFeedResponseItemsItem[] let page 0; for (let i 0; i 5; i) { // 最多翻 5 页 const items await usertagsFeed.items(); // UsertagsFeedResponseItemsItem[] if (items.length 0) break; for (const item of items) { // 1) 图片直链取最高分辨率候选 const imageUrl item.image_versions2.candidates[0].url; // 2) 被标记的人与坐标归一化坐标0~1 const tags item.usertags.in.map(t ({ username: t.user.username, x: Number(t.position[0]), y: Number(t.position[1]), })); // 3) 判断是否为我的照片 const isMine item.photo_of_you; console.log(item.pk, imageUrl, tags, isMine); } page; } })();提示ig.feed是FeedFactory实例见 src/core/feed.factory.ts#L206-L208usertags(id)返回已绑定 client 的UsertagsFeed。JavaScript 使用者将import { A } from b替换为const { A } require(b)即可。五、进阶observable 流式读取与错误重试UsertagsFeedResponseItemsItem同样适用于基类的 RxJS observable 机制src/core/feed.ts#L18-L61适合需要流式消费全部分页数据的场景usertagsFeed.items$ // ObservableUsertagsFeedResponseItemsItem[] .subscribe({ next: (items) { for (const item of items) { // 处理一页 UsertagsFeedResponseItemsItem } }, error: (err) console.error(err), complete: () console.log(all pages consumed), });基类还内置了基于lifeomic/attempt的指数退避重试策略src/core/feed.ts#L10-L17默认delay: 60000、factor: 1.5、maxAttempts: 10并在 src/core/feed.ts#L36-L47 中针对IgResponseError的 400 / 429 / 500 / 502 状态码自动等待重试Instagram 限流时让我们等待。这意味着遍历被标记动态时无需手动处理大部分限流中断。六、与其他模块的呼应读标签、写标签UsertagsFeedResponseItemsItem不仅用于读取我被标记的动态流它与发布侧的标签数据结构也保持一致发布端上传时通过PostingUsertagssrc/types/posting.options.ts#L15-L17提交标签in: Array{ user_id: number | string; position: [number, number] }可见position同样是一对归一化坐标在MediaRepository.configure/configureVideo/configureSidecarsrc/repositories/media.repository.ts#L350-L352、#L383-L385、#L547-L549中usertags参数会在请求前被JSON.stringify序列化后随表单提交——与响应端in[]数组的 JSON 形态一一对应相似结构还出现在LikedFeedResponseUsertagssrc/responses/liked.feed.response.ts#L43与LocationFeedResponseUsertagssrc/responses/location.feed.response.ts#L57中三者共享同一套user position标签模型。因此理解UsertagsFeedResponseItemsItem后你也可以复用同样的标签坐标逻辑去解析点赞流、地点流中的打标数据做到一套逻辑多处复用。七、注意事项与最佳实践字段可选性location、lat、lng为可选字段Optional未标注位置时会缺失preview_comments在无评论时为[]caption在部分场景下可能为空对象读取前建议做空值防御。类型口径差异根接口lng为string而location.lng为number跨结构比较坐标时需统一类型position的联合类型number[] | (number | string)[]同样建议用Number()归一化。分页不要无限翻more_available为 false 时基类自动停止但手动for循环仍建议设上限如示例中的 5 页避免对长历史账号造成过度请求。会话持久化调用ig.state.serialize()保存登录态见 tools/response-to-interface.ts 的用法配合usertagsFeed.serialize()保存分页游标可构建稳定的定时增量抓取任务。相关文档导航根响应结构UsertagsFeedResponseRootObject分页实现类UsertagsFeed子结构接口UsertagsFeedResponseUsertags、UsertagsFeedResponseInItem、UsertagsFeedResponseUser、UsertagsFeedResponsePreviewCommentsItem、UsertagsFeedResponseCaption、UsertagsFeedResponseCandidatesItem客户端入口IgApiClient、FeedFactory相关响应模块responses 模块索引赞分享后端【免费下载链接】instagram-private-apiNodeJS Instagram private API SDK. Written in TypeScript.项目地址https://gitcode.com/gh_mirrors/in/instagram-private-api点击查看免费下载相关推荐instagram-private-api 源码解析HighlightsRepositoryHighlightsTrayResponseCaption 接口全字段详解instagram private api 源码解析HighlightsRepositoryHighlightsTrayResponseCaption 接口全后端instagram-private-api 响应结构详解TagsFeedResponse 标签分栏 Feed 接口全字段解析instagram private api 响应结构详解TagsFeedResponse 标签分栏 Feed 接口全字段解析 导读 TagsFeedRespo后端instagram-private-api 响应接口解析DirectThreadRepositoryUpdateTitleResponseTextAttributesItem 字段详解instagram private api 响应接口解析DirectThreadRepositoryUpdateTitleResponseTextAttrib后端上一篇Cloud Custodian AWS 入门指南编写、运行并监控你的第一个策略下一篇Express中间件机制深度剖析构建高效Web应用的核心原理创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

读完文章,也想定制专属网站?

尧图设计师 24 小时内与您沟通定制方案

免费获取报价 →
↑