【问题标题】:Pagination for Instagram using Facebook Graph API使用 Facebook Graph API 为 Instagram 分页
【发布时间】:2018-12-06 12:48:18
【问题描述】:

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

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

使用我正在调用的 Facebook 的 Graph 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}}

这会成功返回 Instagram 业务帐户中的 25 个最新帖子以及 json 的分页 > 光标部分中的“之后”字段。

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

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

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

我尝试了上述查询的几种变体,试图获取接下来的 25 个帖子,但它们都返回最近的 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)的任何帮助,我们将不胜感激。

谢谢。

【问题讨论】:

  • 我也想知道如何使用分页光标来获取下一个“X”个媒体记录。这有什么好运气吗?

标签: facebook-graph-api instagram


【解决方案1】:

试了很多错误,我想出正确的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}}}}

我也发现可以返回的帖子数量没有限制(我在测试中设法一次返回1000个)

注意:“分页代码”是您执行 API 调用时提供的“之后”代码。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-04
    • 2021-07-19
    • 2020-10-09
    相关资源
    最近更新 更多