使用 Facebook Graph 为 Instagram 分页 API

Pagination for Instagram using Facebook Graph API

我正在尝试使用 Facebook Graph API 为 Instagram 企业帖子发出 API 请求。

https://developers.facebook.com/docs/instagram-api/business-discovery

使用 Facebook 的图表 API 我正在调用 Explorer

    <my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}

这成功地return发送了来自 Instagram 企业帐户的 25 个最新帖子以及 json 的分页 > 光标部分中的 "after" 字段。

但是,我现在正在尝试使用某种形式的分页来获取接下来的 25 个帖子。

我读到 Facebook Graph API 支持基于光标和基于时间的分页,但以下文章建议用于业务发现的 /media 端点仅支持基于光标的分页。

https://developers.facebook.com/docs/instagram-api/reference/user/business_discovery#pagination

我已经尝试了上述查询的几种变体,试图获得接下来的 25 个帖子,但所有这些都是 return 最近的 25 个帖子(与上面的初始查询相同)。

以下是我尝试过的一些查询示例。

    <my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}&after=<after_code_from_first_call>

    <my_facebook_page_id>?fields=business_discovery.username(<instagram_business_account_username>).after(<after_code_from_first_call>){media{comments_count,like_count, caption, media_url, media_type,timestamp}}

因此,对于如何格式化这些查询字符串以便为 instagram 媒体对象执行分页(使用 after/before 参数、时间戳或 post_ids),我们将不胜感激。

谢谢。

经过多次试错,我发现API请求的正确格式应该如下

https://graph.facebook.com/v3.0/<my-facebook-page-id>?access_token=<access-token>&fields=business_discovery.username(<accountHandle>){{profile_picture_url,media.after(<pagination-code>).limit(<the-amount-of-posts-to-return>){{id,caption,media_url,media_type,like_count,comments_count,timestamp,permalink}}}}

我还发现可以 returned 的帖子数量没有限制(我在测试中一次 return 1000)

注意:"pagination-code" 是在您进行 API 调用时提供的 "after" 代码。