You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Power Query自定义连接器如何读取JSON响应体分页参数实现分页

Power Query 处理Vimeo API响应体内分页字段实现方法

M语言没有提供专门读取JSON响应体分页字段的内置辅助函数,但你不需要修改原有Table.GenerateByPage的分页遍历框架,只需要调整单页请求函数里下一页链接的提取逻辑,把原来从响应头取Link的步骤,改成从解析后的JSON结构中取值即可,和原有元数据传参的逻辑完全兼容。

核心调整逻辑

原Github示例的逻辑是「请求响应→从响应头元数据提取下一页链接→解析JSON转表」,针对Vimeo的响应结构只需要把顺序调整为「请求响应→解析JSON结构→从JSON的paging字段提取下一页链接→提取业务数据转表」即可,注意Vimeo返回的next字段是相对路径,需要拼接API根域名转成完整请求地址。

可直接复用的实现代码

// 单页请求函数,替换原示例中的Github.Contents
Vimeo.Contents = (url as text) as table =>
    let
        response = Web.Contents(url),
        jsonResponse = Json.Document(response),
        // 提取业务数据数组,Vimeo列表接口的实际数据默认存放在data字段
        dataList = jsonResponse[data],
        dataTable = Table.FromList(dataList, Splitter.SplitByNothing()),
        // 从响应体提取下一页相对路径,拼接成完整API地址
        nextRelativePath = jsonResponse[paging][next]?,
        nextLink = if nextRelativePath <> null then "https://api.vimeo.com" & nextRelativePath else null
    in
        // 下一页链接存入元数据,和原示例的元数据结构保持一致
        dataTable meta [Next=nextLink];

// 分页遍历函数,逻辑和原示例几乎一致,无需大幅修改
Vimeo.PagedTable = (initialUrl as text) as table =>
    Table.GenerateByPage((previous) =>
        let
            next = if (previous <> null) then Value.Metadata(previous)[Next] else null,
            urlToUse = if (next <> null) then next else initialUrl,
            // 无下一页时返回null,终止分页迭代
            current = if (previous <> null and next = null) then null else Vimeo.Contents(urlToUse),
            currentNext = if (current <> null) then Value.Metadata(current)[Next] else null
        in
            current meta [Next=currentNext]
    );

注意事项

  • 如果你对接的Vimeo接口业务数据不在data字段下,把代码中jsonResponse[data]替换为对应字段名即可。
  • 不要直接使用返回的相对路径发起请求,必须拼接Vimeo API根地址https://api.vimeo.com,否则会因地址不合法请求失败。
  • 如果需要使用总条数、当前页码、每页条数这类分页元数据,可以在解析JSON时一并提取,存入表的meta字段中,后续通过Value.Metadata(表名)即可读取。
  • 如果你已经为连接器配置了OAuth2认证,Web.Contents会自动携带鉴权上下文,拼接后的完整地址不需要额外追加认证参数。

内容的提问来源于stack exchange,提问作者Overfloweth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.03 10:39:32