instagram-private-api 位置 Story 响应结构全解析:LocationRepositoryStoryResponseStory 接口字段详解与实战
instagram-private-api 位置 Story 响应结构全解析:LocationRepositoryStoryResponseStory 接口字段详解与实战
本文面向使用 instagram-private-api(NodeJS Instagram 私有 API SDK,TypeScript 编写)的开发者,深入剖析 LocationRepositoryStoryResponseStory 这一响应接口:它承载了「按地理位置拉取 Story(地点聚合快拍)」请求返回的单个故事集合对象。读完本文,你将掌握该接口 13 个属性的完整含义与类型约束、它与 items/owner/location 等子结构之间的层级关系,以及从位置搜索到 Story 内容提取(图片、视频、贴纸坐标)的完整调用链与可运行示例。
一、接口定位:位置 Story 响应的核心载体
在 Instagram 中,除了用户主页 Story(reel)和 Hashtag 聚合 Story 之外,还存在位置聚合 Story(Location Story)——即围绕某个地理地点(POI)聚合的公开快拍合集。LocationRepositoryStoryResponseStory 正是 SDK 中该能力返回结构的核心对象。
从源码可以看出,完整响应被组织为根对象 + 故事对象的双层结构(见 src/responses/location.repository.story.response.ts):
export interface LocationRepositoryStoryResponseRootObject {
story: LocationRepositoryStoryResponseStory;
status: string;
}
export interface LocationRepositoryStoryResponseStory {
id: string;
latest_reel_media: number;
expiring_at: number;
seen: number;
can_reply: boolean;
can_reshare: boolean;
reel_type: string;
owner: LocationRepositoryStoryResponseOwner;
location: LocationRepositoryStoryResponseLocation;
items: LocationRepositoryStoryResponseItemsItem[];
prefetch_count: number;
unique_integer_reel_id: string;
has_pride_media: boolean;
}
接口文档 docs/interfaces/responses/LocationRepositoryStoryResponseStory.md 与 LocationRepositoryStoryResponseRootObject.md 完整记录了这 13 个属性,且每项都标注了其在源码中的精确定义行号。也就是说,story 字段是「本次位置故事聚合」的元信息与内容清单,status 字段则是 Instagram 接口通用的状态标识(请求成功时通常为 'ok',SDK 在 src/core/request.ts 中依据它判定请求是否成功)。
二、13 个属性逐一拆解
以下按接口文档(LocationRepositoryStoryResponseStory.md)的字段顺序,给出类型、含义与使用建议。
| 属性名 | 类型 | 含义与使用建议 |
|---|---|---|
id |
string |
该位置 Story 聚合的唯一标识(reel id)。注意这里是字符串,而 unique_integer_reel_id 是纯数字形式;两者可用于去重与缓存键。 |
latest_reel_media |
number |
最新一条 Story 媒体的时间戳(Unix 秒)。可据此判断该位置是否有新内容。 |
expiring_at |
number |
整个 Story 聚合的过期时间戳(Unix 秒)。快拍 24 小时机制,过期后该响应通常不再有效。 |
seen |
number |
当前登录用户已看过该聚合内多少条内容(服务端返回的已读计数),可用于「是否全部已读」的展示逻辑。 |
can_reply |
boolean |
当前用户是否可对这条 Story 进行回复(快拍回复/表情回应)。 |
can_reshare |
boolean |
当前用户是否可转发/分享这条 Story 到自己的快拍。 |
reel_type |
string |
Story 集合类型标识,位置聚合场景下为 location_aggregate 一类取值;可据此区分用户快拍与聚合快拍。 |
owner |
LocationRepositoryStoryResponseOwner |
该位置的「所有者」信息对象,包含 type、pk、name、头像 URL、经纬度以及内嵌的 location_dict 详细地点字典。 |
location |
LocationRepositoryStoryResponseLocation |
地点对象,携带 pk、name、short_name、lng、lat 以及可选的 address、city、external_source、facebook_places_id 等地址信息。 |
items |
LocationRepositoryStoryResponseItemsItem[] |
核心内容数组:该位置聚合下的每一条 Story 媒体(图片/视频),字段极丰富,详见下一节。 |
prefetch_count |
number |
客户端预取数量建议,供前端决定预加载多少条内容。 |
unique_integer_reel_id |
string |
与 id 对应的纯数字形式 reel id(字符串包装),用于需要数值型 id 的场景。 |
has_pride_media |
boolean |
该聚合是否包含「骄傲月(Pride)」主题媒体,用于特殊运营内容的标记。 |
值得注意的类型细节:id 与 unique_integer_reel_id 均为字符串。这是因为 Instagram 返回的某些 ID 数值超过 Number.MAX_SAFE_INTEGER,SDK 在 src/core/request.ts 中使用 json-bigint 的 storeAsString 配置将超长数字自动包装成字符串,避免精度丢失——这也是整个响应体系中大量 ID 字段采用 string 类型的根本原因。
三、items:每条位置 Story 媒体的完整字段
items 数组中的每个元素 LocationRepositoryStoryResponseItemsItem(源码见 location.repository.story.response.ts,接口文档见 LocationRepositoryStoryResponseItemsItem.md)是实际可消费的媒体数据,它比外层 story 更贴近业务,主要字段分组如下:
基础标识:
pk(string)与id(string):媒体主键与完整 idcode(string):媒体短码(可用于拼接instagram.com/p/{code}类链接)taken_at(number)、device_timestamp(string)、imported_taken_at(number)、expiring_at(number):拍摄时间、设备时间戳、导入时间与过期时间media_type(number):媒体类型(1=图片,2=视频),是判断后续读取图片字段还是视频字段的第一依据filter_type(number)、client_cache_key(string):滤镜编号与客户端缓存键organic_tracking_token(string):追踪 token,可用于上报曝光
媒体资源:
image_versions2(LocationRepositoryStoryResponseImage_versions2):图片多分辨率候选,内部candidates数组每一项含width、height、url与可选的estimated_scans_sizes- 视频相关字段均为可选:
video_versions(LocationRepositoryStoryResponseVideoVersionsItem[])、video_dash_manifest、video_codec、video_duration、has_audio、is_dash_eligible、number_of_qualities——只有当media_type为视频时才会出现 original_width/original_height(number):原始画幅
作者与互动:
user(LocationRepositoryStoryResponseUser):发布者信息(pk、username、full_name、is_private、is_verified、头像 URL 等)caption:此处固定为null(快拍通常无长文案);caption_is_edited、caption_position保留can_viewer_save、can_reply、can_reshare、supports_reel_reactions(boolean)、show_one_tap_fb_share_tooltip(boolean)、has_shared_to_fb(number):保存、回复、转发、反应等权限开关photo_of_you、is_reel_media、is_pride_media(boolean):标记字段
贴纸/交互图层(可选):
story_locations(LocationRepositoryStoryResponseStoryLocationsItem[]):位置贴纸,含x/y/z/width/height/rotation/is_pinned/is_hidden/is_sticker等排版属性及嵌套的location对象story_hashtags(LocationRepositoryStoryResponseStoryHashtagsItem[]):话题贴纸,排版属性 + 嵌套hashtag(name、id)reel_mentions(LocationRepositoryStoryResponseReelMentionsItem[]):@提及贴纸,排版属性 + 嵌套user
这些贴纸数组与 sticker-builder(发布侧贴纸构建)遥相呼应:一个负责读取、一个负责生成,共同构成快拍交互层的数据模型。
四、owner 与 location:地点的双重身份
story.owner(LocationRepositoryStoryResponseOwner.md)与 story.location(LocationRepositoryStoryResponseLocation.md)看起来相似,实则分工不同:
- owner 代表「这个聚合由哪个地点实体拥有」,字段固定必填:
type(如location)、pk、name、short_name、profile_pic_url、profile_pic_username、lng(string)、lat(number),并内嵌完整的location_dict(LocationRepositoryStoryResponseLocation_dict.md)——后者包含pk、name、address、city、short_name、lng、lat、external_source、facebook_places_id。 - location 则是「本次内容关联的地点对象」,大部分字段可选:
type?、profile_pic_url?、profile_pic_username?、location_dict?、address?、city?、external_source?、facebook_places_id?,必填的仅pk、name、short_name、lng、lat。注意lng的类型是string | number联合类型——服务端在不同场景可能返回字符串或数值,代码中需做统一处理。
此外,items 内贴纸里嵌套的 location 复用了同一接口,因此在数据流上它是整个响应中被复用次数最多的地点模型。
五、调用链:从位置搜索到 Story 内容提取
要拿到 LocationRepositoryStoryResponseStory,需要经过如下链路(全部围绕 LocationRepository 与 LocationSearch):
- 搜索地点:
client.locationSearch.index(latitude, longitude, searchQuery?)调用GET /api/v1/location_search/,返回 LocationRepositorySearchResponseRootObject,从中取venues[]得到地点pk与坐标。 - 获取位置 Story:
client.location.story(id)调用GET /api/v1/locations/${id}/story/(见 location.repository.ts),返回LocationRepositoryStoryResponseRootObject,story即本文核心接口。
完整可运行示例(SDK 初始化参考 examples/session.example.ts):
import { IgApiClient } from './src';
(async () => {
const ig = new IgApiClient();
ig.state.generateDevice(process.env.IG_USERNAME);
await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
// 1. 通过坐标 + 关键词搜索地点(服务层封装见 src/services/search.service.ts)
const { venues } = await ig.locationSearch.index(31.2304, 121.4737, '上海');
const venue = venues[0];
console.log(venue.name, venue.location?.pk ?? venue.pk);
// 2. 拉取该地点的 Story 聚合
const { story, status } = await ig.location.story(venue.location?.pk ?? venue.pk);
console.log('status:', status);
console.log('story id:', story.id, '| 过期时间:', new Date(story.expiring_at * 1000).toISOString());
// 3. 遍历 items,按媒体类型提取资源
for (const item of story.items) {
if (item.media_type === 2) {
// 视频:取最高分辨率版本
const best = item.video_versions?.[0];
console.log(`[video] ${item.user.username}: ${best?.url}`);
} else {
// 图片:取最大分辨率候选
const best = item.image_versions2.candidates.reduce((a, b) => (a.width > b.width ? a : b));
console.log(`[photo] ${item.user.username}: ${best.url}`);
}
// 贴纸坐标同样可用:item.story_locations / item.story_hashtags / item.reel_mentions
}
await ig.destroy();
})();
使用注意:
story()接受number | string类型的地点 id;若响应不存在(该地点当前无快拍),SDK 会按 src/core/request.ts 的错误映射抛出IgNotFoundError(404)等错误,调用方应做容错。- 所有请求都携带 SDK 自动生成的设备信息、签名与头(见 src/core/client.ts 中
state、request与各 repository 的装配,以及 request.ts 的默认头),无需手动处理 Cookie 与签名。
六、结构速查表与进一步阅读
LocationRepositoryStoryResponseStory 及周边接口形成了清晰的树状结构,可用一张表快速定位(均为仓库内真实存在的文档/源码路径):
| 层级 | 接口 | 文档 | 源码定义行 |
|---|---|---|---|
| 根 | LocationRepositoryStoryResponseRootObject |
RootObject.md | story.response.ts:1-4 |
| 主体 | LocationRepositoryStoryResponseStory |
Story.md | story.response.ts:5-19 |
| 所有者 | LocationRepositoryStoryResponseOwner |
Owner.md | story.response.ts:20-30 |
| 地点 | LocationRepositoryStoryResponseLocation |
Location.md | story.response.ts:42-56 |
| 媒体 | LocationRepositoryStoryResponseItemsItem |
ItemsItem.md | story.response.ts:57-95 |
若你的业务同时涉及发布侧,可对比 sticker-builder 模块中的 LocationSticker、HashtagSticker、MentionSticker 等贴纸模型,它们与上文 story_locations/story_hashtags/reel_mentions 的字段语义高度一致,便于构建「读取-解析-再生成」的完整闭环。