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

后端聊天机器人如何通过官方Instagram API获取Reel播放量?

获取Instagram Reel播放量的官方后端方案

官方可行路径:Instagram Graph API + 应用级令牌

目前官方唯一支持无用户交互后端场景的方案是Instagram Graph API,但有硬性前提:你要查询的Reel必须属于已绑定到Facebook Business Manager的Instagram Business/Creator账号——普通个人账号的Reel无法通过官方API获取播放量。

配置与调用步骤

  1. 基础准备

    • 注册Facebook开发者账号,创建Business类型应用。
    • 将目标Instagram Business/Creator账号关联到一个Facebook Page,再把该Page绑定到你的应用。
    • 在应用的「权限与功能」中申请并通过审核以下权限:
      • instagram_basic:读取Instagram账号基础信息
      • pages_read_engagement:读取关联Page的内容权限
      • instagram_manage_insights:获取媒体洞察数据(含播放量)
  2. 获取应用级令牌
    在Facebook开发者平台的「Access Token Tool」中选择你的应用,生成App Access Token——这个令牌无需用户授权,可直接在后端长期使用(需定期刷新)。

  3. 获取Instagram账号ID
    调用Graph API获取绑定到Page的Instagram账号ID:

    GET https://graph.facebook.com/v18.0/{PAGE_ID}/instagram_accounts?access_token={APP_ACCESS_TOKEN}
    

    解析返回JSON中的id字段即为Instagram账号ID。

  4. 获取Reel的媒体ID
    若已知Reel的公开URL,可通过oEmbed接口快速获取媒体ID:

    GET https://graph.facebook.com/v18.0/instagram_oembed?url={REEL_URL}&access_token={APP_ACCESS_TOKEN}
    

    返回结果中的media_id就是目标Reel的唯一标识。

  5. 拉取播放量数据
    调用洞察接口获取播放量:

    GET https://graph.facebook.com/v18.0/{REEL_MEDIA_ID}/insights?metric=plays&access_token={APP_ACCESS_TOKEN}
    

    解析返回JSON中data[0].values[0].value字段,即为该Reel的播放量数值。

Java实现示例(OkHttp版)

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.IOException;

public class ReelPlayCounter {
    private static final String APP_ACCESS_TOKEN = "替换为你的应用级令牌";
    private static final String PAGE_ID = "替换为关联的Facebook Page ID";
    private static final String REEL_URL = "替换为目标Reel的公开URL";
    private static final ObjectMapper mapper = new ObjectMapper();
    private static final OkHttpClient client = new OkHttpClient();

    public static void main(String[] args) throws IOException {
        // 1. 获取Instagram账号ID
        String igAccountId = getInstagramAccountId();
        // 2. 获取Reel媒体ID
        String reelMediaId = getReelMediaId();
        // 3. 获取播放量
        long playCount = getReelPlayCount(reelMediaId);
        System.out.printf("Reel播放量:%d%n", playCount);
    }

    private static String getInstagramAccountId() throws IOException {
        Request request = new Request.Builder()
                .url(String.format("https://graph.facebook.com/v18.0/%s/instagram_accounts?access_token=%s", PAGE_ID, APP_ACCESS_TOKEN))
                .build();
        try (Response response = client.newCall(request).execute()) {
            JsonNode root = mapper.readTree(response.body().string());
            return root.get("data").get(0).get("id").asText();
        }
    }

    private static String getReelMediaId() throws IOException {
        Request request = new Request.Builder()
                .url(String.format("https://graph.facebook.com/v18.0/instagram_oembed?url=%s&access_token=%s", REEL_URL, APP_ACCESS_TOKEN))
                .build();
        try (Response response = client.newCall(request).execute()) {
            JsonNode root = mapper.readTree(response.body().string());
            return root.get("media_id").asText();
        }
    }

    private static long getReelPlayCount(String reelMediaId) throws IOException {
        Request request = new Request.Builder()
                .url(String.format("https://graph.facebook.com/v18.0/%s/insights?metric=plays&access_token=%s", reelMediaId, APP_ACCESS_TOKEN))
                .build();
        try (Response response = client.newCall(request).execute()) {
            JsonNode root = mapper.readTree(response.body().string());
            return root.get("data").get(0).get("values").get(0).get("value").asLong();
        }
    }
}

重要限制说明

  • 官方API仅支持查询自身或已授权的Business/Creator账号的Reel播放量,无法获取普通个人账号的公开Reel数据。
  • 应用权限需要Facebook审核,审核周期通常为1-3个工作日。
  • 应用级令牌需定期在开发者平台刷新,避免过期失效。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.26 11:16:28