直播视频排期

v12.0 的定时直播视频现已停用,所有版本的定时直播视频将在 2021 年 12 月 14 日停用。使用 planned_start_time 参数调用 POST /ID/live-video 端点会返回错误提示。

您可使用直播视频 API 创建将于预定时间开始直播的直播视频,预定时间可为自创建日期起七天内的任何时间。

直播视频排期

如要在“用户”、“主页”、“小组”或“活动”页面上创建将于未来某日开始直播的直播视频,请发送请求至:

POST /{node-id}/live_videos?status=SCHEDULED_UNPUBLISHED&planned_start_time={start-time}

使用 planned_start_time 参数和 UNIX 时间戳指明所需的开始时间。

这样将在目标节点上创建 LiveVideo 对象,并返回直播视频的 secure_stream_urlid。在安排开始时间或在此之前,结合使用安全直播网址与编码器,以将直播视频数据投射到 LiveVideo 对象。只要直播视频接收到直播数据,该视频便会在预定开始时间出现在节点时间线/动态中。

已作出排期的直播视频可在开始日期之前的任意时间接收直播数据,以用于预览。

请求示例

curl -i -X POST \ 
  "https://graph.facebook.com/{page-id}/live_videos?status=SCHEDULED_UNPUBLISHED&planned_start_time=1541539800&access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{page-id}/live_videos",
  new JSONObject("{\"status\":\"SCHEDULED_UNPUBLISHED\",\"planned_start_time\":\"1541539800\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{page-id}/live_videos"
           parameters:@{ @"status": @"SCHEDULED_UNPUBLISHED",@"planned_start_time": @"1541539800",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{page-id}/live_videos',
  'POST',
  {"status":"SCHEDULED_UNPUBLISHED","planned_start_time":"1541539800"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{page-id}/live_videos',
    array (
      'status' => 'SCHEDULED_UNPUBLISHED',
      'planned_start_time' => '1541539800'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

响应示例

{
  "id": "10214937378883406",  //LiveVideo object ID
  "stream_url": "rtmp://rtmp-api.facebook...",
  "secure_stream_url": "rtmps://rtmp-api.facebook..."  //Stream URL
}

要获取已作出排期的直播视频列表,请参阅获取已作出排期的直播视频

预览直播视频

您可使用直播视频 API 预览未发布的直播视频;在创建此类 LiveVideo 对象时,其 status 设为 SCHEDULED_UNPUBLISHEDUNPUBLISHED

如要预览未发布的直播视频,请发送请求至:

GET /{live_video_id}?fields={fields}

使用 {fields} 参数获取 LiveVideo 对象的 dash_preview_url

请求示例

curl -i -X GET \
 "https://graph.facebook.com/{live-video-id}
    ?fields=dash_preview_url
     &access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{live-video-id}",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "dash_preview_url");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}"
           parameters:@{ @"fields": @"dash_preview_url",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}',
  'GET',
  {"fields":"dash_preview_url"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{live-video-id}',
    '{fields:dash_preview_url}',    
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

响应示例

{
  'dash_preview_url': 'https://video.xx.fbcdn.net/...',
  'id': '{live-video-id}'
}

这样将返回直播视频的 dash_preview_urlid。复制此网址并粘贴到 Dash Player,以预览直播视频。

尽管使用第三方测试播放器预览直播视频能够有效验证直播视频内容,但我们仍建议您在测试主页上播放。您必须取得主页管理员或编辑身份,以便在主页上播放。此外,您还可设置隐私参数,以创建仅对您本人显示的投射视频。

获取已作出排期的直播视频

要获取“用户”、“主页”、“小组”或“活动”页面上已作出排期的直播视频列表,请先取得具有 publish_video 权限的相应访问口令,并发送请求至:

GET /{node-id}/live_videos?broadcast_status=["SCHEDULED_UNPUBLISHED"]

注意,broadcast_status 值必须为数组。请参阅 LiveVideo 参考文档,获取其他值的完整列表。

主页直播视频示例列表

curl -i -X GET \ 
  "https://graph.facebook.com/{page-id}/live_videos?broadcast_status=["SCHEDULED_UNPUBLISHED"]&access_token={access-token}"
GraphRequest request = GraphRequest.newGraphPathRequest(
  accessToken,
  "/{page-id}/live_videos",
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});

Bundle parameters = new Bundle();
parameters.putString("broadcast_status", "["SCHEDULED_UNPUBLISHED"]");
request.setParameters(parameters);
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{your-page-id}/live_videos"
           parameters:@{ @"broadcast_status": @"["SCHEDULED_UNPUBLISHED"]",}
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{page-id}/live_videos',
  'GET',
  {"broadcast_status":"[\"SCHEDULED_UNPUBLISHED\"]"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{your-page-id}/live_videos',
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

响应示例

{
  "data": [
    {
      "status": "SCHEDULED_UNPUBLISHED",
      "stream_url": "rtmp://rtmp-api-dev.facebook.com:80/rtmp/...",
      "secure_stream_url": "rtmps://rtmp-api-dev.facebook.com:443/rtmp/...",
      "embed_html": "<iframe src=\"https://www.facebook.com/plugins/video.php?...",
      "id": "10214937378883406 "  //LiveVideo object ID
    }
  ]
}

为直播视频重新排期

若要为已作出排期的直播视频更改开始时间,您可发送请求至:

POST /{live-video-id}?planned_start_time={new-start-time}

{new-start-time} 值必须为 UNIX 时间戳,用于表明新的开始时间。成功后,此 API 将在响应中提供 LiveVideo 对象编号。

主页直播视频示例

curl -i -X POST \
  "https://graph.facebook.com/{live-video-id}?planned_start_time=1541540800&access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{live-video-id}",   
  new JSONObject("{\"planned_start_time\":\"1541540800\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}"    
           parameters:@{ @"planned_start_time": @"1541540800",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}', 
  'POST',
  {"planned_start_time":"1541540800"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{live-video-id}', 
    array (
      'planned_start_time' => '1541540800'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

响应示例

{
  "id": "10214937378883406"
}

立即开始直播视频

若要立即开始直播视频,您可发送请求至:

POST /{live-video-id}?status=LIVE_NOW

在与表示直播视频的 LiveVideo 对象相关联的直播网址接收到直播数据后,系统便会开始直播此视频。成功后,此 API 将在响应中提供 LiveVideo 对象编号。

请求示例

curl -i -X POST \
 "https://graph.facebook.com/{live-video-id}?status=LIVE_NOW&access_token={access-token}"
GraphRequest request = GraphRequest.newPostRequest(
  accessToken,
  "/{live-video-id}",
  new JSONObject("{\"status\":\"LIVE_NOW\"}"),
  new GraphRequest.Callback() {
    @Override
    public void onCompleted(GraphResponse response) {
      // Insert your code here
    }
});
request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}"
           parameters:@{ @"status": @"LIVE_NOW",}
           HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}',
  'POST',
  {"status":"LIVE_NOW"},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->post(
    '/{live-video-id}',
    array (
      'status' => 'LIVE_NOW'
    ),
    '{access-token}'
  );
} catch(FacebookExceptionsFacebookResponseException $e) {
  echo 'Graph returned an error: ' . $e->getMessage();
  exit;
} catch(FacebookExceptionsFacebookSDKException $e) {
  echo 'Facebook SDK returned an error: ' . $e->getMessage();
  exit;
}
$graphNode = $response->getGraphNode();

JSON 响应示例

{
  "id": "10214937378883406"
}