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

NestJS集成Facebook Live评论SSE服务返回400错误的排查求助

NestJS集成Facebook Live评论SSE服务返回400错误的排查求助

各位大佬好,我最近在做一个NestJS项目,想要通过SSE实现Facebook Live评论的实时推送,但每次请求我的SSE代理接口都会返回400错误,折腾了好几天都没找到问题所在,特意来求助!

问题背景

  • 我的项目是基于NestJS开发的,本地运行在localhost:3000,线上环境测试时也遇到同样的问题
  • 使用的是页面访问令牌,已经通过Facebook官方工具验证过令牌有效,且拥有文档中要求的所有权限
  • 通过Page API的live_video接口可以正常获取直播ID/视频ID,而且用普通HTTP请求调用该ID的评论接口能成功拿到数据,但换成SSE流的方式就一直报400

我写的代理接口代码

@Get('proxy')
async streamFacebookSSE(@Res() res: Response, @Req() req: Request) {
  const accessToken = 'abc123';
  const liveVideoId = 'liveId';
  const sseUrl = `https://streaming-graph.facebook.com/${liveVideoId}/live_comments?access_token=${accessToken}`;

  try {
    const es = createEventSource({
      url: sseUrl,
      fetch: (input, init) => fetch(input, {
        ...init,
        headers: {
          ...init.headers,
          Accept: 'text/event-stream',
          'User-Agent': 'hardlevel-client/1.0',
        },
      }),
      onMessage: ({ data, event, id }) => {
        console.log('📥 收到评论:', data);
        res.write(`data: ${data}\n\n`); // 将数据推送给客户端SSE
      },
    });

    console.log(es.readyState);
    console.log(es.lastEventId);

    let seenMessages = 0;
    for await (const { data, event, id } of es) {
      console.log('Data: %s', data);
      console.log('Event ID: %s', id); // 注意:可能为undefined
      console.log('Event: %s', event); // 注意:可能为undefined

      if (++seenMessages === 10) {
        break;
      }
    }

    es.close();
    console.log('✅ SSE连接成功。');
  } catch (error) {
    console.error('🚨 启动SSE连接失败:', error);
  }
}

已经做过的排查

  • 反复确认访问令牌的有效性,以及是否包含pages_show_list、pages_read_engagement等文档要求的权限
  • 验证live_video返回的ID是正确的,用该ID调用普通HTTP评论接口能正常返回数据
  • 本地和线上环境都测试过,问题完全一致
  • 请求头中已经设置了Accept: text/event-stream,也添加了自定义的User-Agent

有没有大佬遇到过类似的问题?或者能给我一些新的排查方向吗?

内容来源于stack exchange

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.08 14:39:36