小程序开放平台

文档中心
基础
路由
跳转
转发
界面
网络
支付
数据缓存
媒体
位置
开放接口
登录
授权
设置
收货地址
用户信息
帐号信息
引导关注
专业号
服务组件
直播预约/跳转/打开
直播预约/跳转/回放
设备
XHSML
性能
第三方平台
文件
数据分析
画布

直播预约/跳转/回放

开发
>
JS API
>
开放接口
>
直播预约/跳转/打开
>
直播预约/跳转/回放
>
更新时间:2025-03-27 21:54:05

xhs.reserveLivestream

基础库版本 >= 3.120.0, 小红书 App 版本 >= 8.76 开始支持本方法。

用于预约直播,用户可以通过

trailerId
进行预约。


语法

handleLiveBooking() {
  if (!this.data.trailerId) {
    xhs.showToast({ title: '请先获取 trailerId' });
    return;
  }

  let _this = this;

  xhs.reserveLivestream({ 
    trailerId: String(_this.data.trailerId),
    success(res) {
      console.log('reserveLivestream success', res);
      _this.setData({ trailerInfo: '获取 trailerInfo 信息成功:' + JSON.stringify(res) });
    },
    fail(err) {
      console.log('reserveLivestream fail', err);
      _this.setData({ trailerInfo: '获取 trailerInfo 信息失败:' + JSON.stringify(err) });
    }
  });
}

参数说明

options
object
类型,属性如下:

属性名
类型
必填
说明
最低支持版本
trailerIdstring直播预约 ID3.120.x
successFunction接口调用成功的回调函数3.120.x
failFunction接口调用失败的回调函数3.120.x
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)3.120.x

回调成功

属性
类型
说明
最低支持版本
errMsgstringreserveLivestream:ok3.120.x
statusnumber调用状态码 status3.120.x

回调失败

属性
类型
说明
最低支持版本
errMsgstringreserveLivestream:fail + 错误信息3.120.x

Bug & Tip

  • tip:
    trailerId
    不能为空,否则调用会失败。

xhs.openLivestream

基础库版本>= 3.120.0,小红书 App 版本 >= 8.76 开始支持本方法。

用于跳转直播间,用户可以通过

roomId
进入直播间。


语法

handleLiveJump() {
  if (!this.data.roomId) {
    xhs.showToast({ title: '请先获取 roomId' });
    return;
  }

  let _this = this;
  xhs.openLivestream({ 
    roomId: String(_this.data.roomId),
    success(res) {
      console.log('openLivestream success', res);
      _this.setData({ jumpInfo: `跳转直播间成功[${_this.data.roomId}]: ${JSON.stringify(res)}` });
    },
    fail(err) {
      console.log('openLivestream fail', err);
      _this.setData({ jumpInfo: `跳转直播间失败[${_this.data.roomId}]: ${JSON.stringify(err)}` });
    }
  });
}

参数说明

属性名
类型
必填
说明
最低支持版本
roomIdstring直播间 ID3.120.x
successFunction接口调用成功的回调函数3.120.x
failFunction接口调用失败的回调函数3.120.x
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)3.120.x

回调成功

属性
类型
说明
最低支持版本
errMsgstringopenLivestream:ok3.120.x
statusnumber调用状态码 status3.120.x

回调失败

属性
类型
说明
最低支持版本
errMsgstringopenLivestream:fail + 错误信息3.120.x

Bug & Tip

  • tip:
    roomId
    不能为空,否则调用会失败。

xhs.replayLivestream

基础库版本 >= 3.120.0,小红书 App 版本 >= 8.76 开始支持本方法。

用于回放直播,用户可以通过

roomId
进入直播回放。


语法

handleLiveReplay() {
  if (!this.data.roomId) {
    xhs.showToast({ title: '请先获取 roomId' });
    return;
  }

  let _this = this;
  xhs.replayLivestream({ 
    roomId: String(_this.data.roomId),
    success(res) {
      console.log('replayLivestream success', res);
      _this.setData({ replayInfo: `跳转直播间回放成功[${_this.data.roomId}]: ${JSON.stringify(res)}` });
    },
    fail(err) {
      console.log('replayLivestream fail', err);
      _this.setData({ replayInfo: `跳转直播间回放失败[${_this.data.roomId}]: ${JSON.stringify(err)}` });
    }
  });
}

参数说明

属性名
类型
必填
说明
最低支持版本
roomIdstring直播间 ID3.120.x
successFunction接口调用成功的回调函数3.120.x
failFunction接口调用失败的回调函数3.120.x
completeFunction接口调用结束的回调函数(调用成功、失败都会执行)3.120.x

回调成功

属性
类型
说明
最低支持版本
errMsgstringreplayLivestream:ok3.120.x
statusnumber调用状态码 status3.120.x

回调失败

属性
类型
说明
最低支持版本
errMsgstringreplayLivestream:fail + 错误信息3.120.x

Bug & Tip

  • tip:
    roomId
    不能为空,否则调用会失败。