Lên lịch phát trực tiếp

Tính năng lên lịch phát video trực tiếp đã ngừng hoạt động trong phiên bản 12.0 và sẽ ngừng hoạt động trong mọi phiên bản vào ngày 14/12/2021. Các lệnh gọi đến điểm cuối POST /ID/live-video bằng thông số planned_start_time sẽ trả về lỗi.

Bạn có thể sử dụng API Video trực tiếp để tạo video sẽ phát trực tiếp vào thời gian định sẵn, tối đa là 7 ngày kể từ ngày tạo.

Lên lịch phát trực tiếp

Để tạo video phát trực tiếp về Người dùng, Trang, Nhóm hoặc Sự kiện với ngày bắt đầu trong tương lai, hãy gửi yêu cầu đến:

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

Sử dụng thông số planned_start_time và nhãn thời gian UNIX để biểu thị thời gian bắt đầu mong muốn.

Thao tác này sẽ tạo đối tượng LiveVideo trên nút được nhắm đến và trả về secure_stream_url cũng như id của video trực tiếp. Sử dụng URL luồng bảo mật với bộ mã hóa của bạn để phát dữ liệu video trực tiếp sang đối tượng LiveVideo vào hoặc trước thời gian bắt đầu đã lên lịch. Nội dung phát sẽ xuất hiên trên bảng tin/dòng thời gian của nút vào thời gian bắt đầu dự kiến, miễn là nội dung đó nhận được dữ liệu phát trực tiếp.

Để phục vụ cho mục đích xem trước, các nội dung phát đã lên lịch có thể nhận được dữ liệu phát trực tiếp ở bất kỳ điểm nào trước ngày bắt đầu.

Yêu cầu mẫu

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();

Phản hồi mẫu

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

Để lấy danh sách các nội dung phát đã lên lịch, hãy xem phần Lấy nội dung phát đã lên lịch.

Xem trước nội dung phát

Bạn có thể sử dụng API Video trực tiếp để xem trước video phát trực tiếp chưa đăng; đối tượng LiveVideo đã tạo có status được đặt thành SCHEDULED_UNPUBLISHED hoặc UNPUBLISHED.

Để xem trước video phát trực tiếp chưa đăng, hãy gửi yêu cầu đến:

GET /{live_video_id}?fields={fields}

Sử dụng thông số {fields} để lấy dash_preview_url của đối tượng LiveVideo.

Yêu cầu mẫu

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();

Phản hồi mẫu

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

Thao tác này sẽ trả về dash_preview_urlid của video trực tiếp. Sao chép và dán URL vào Dash Player để xem trước nội dung phát.

Mặc dù việc xem trước nội dung phát bằng trình phát thử nghiệm của bên thứ ba là một cách hữu hiệu để xác minh nội dung phát, nhưng bạn nên phát trên trang thử nghiệm. Bạn phải là biên tập viên hoặc quản trị viên của trang thì mới phát trực tiếp được trên trang. Ngoài ra, bạn có thể đặt thông số quyền riêng tư để tạo video phát trực tiếp mà chỉ bạn mới nhìn thấy.

Lấy nội dung phát đã lên lịch

Để lấy danh sách các nội dung phát đã lên lịch cho Người dùng, Trang, Nhóm hoặc Sự kiện, hãy lấy mã truy cập phù hợp cùng với quyền publish_video và gửi yêu cầu đến:

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

Lưu ý rằng giá trị broadcast_status phải là một mảng. Hãy xem tài liệu tham khảo về LiveVideo để biết toàn bộ danh sách các giá trị bổ sung.

Danh sách nội dung phát mẫu dành cho Trang

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();

Phản hồi mẫu

{
  "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
    }
  ]
}

Lên lại lịch phát trực tiếp

Bạn có thể thay đổi thời gian bắt đầu của nội dung phát đã lên lịch bằng cách gửi yêu cầu đến:

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

Giá trị {new-start-time} phải là nhãn thời gian UNIX biểu thị thời gian bắt đầu mới. Khi thành công, API sẽ phản hồi bằng ID của đối tượng LiveVideo.

Video trực tiếp mẫu dành cho Trang

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();

Phản hồi mẫu

{
  "id": "10214937378883406"
}

Bắt đầu phát trực tiếp ngay lập tức

Bạn có thể bắt đầu phát trực tiếp ngay lập tức bằng cách gửi yêu cầu đến:

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

Nội dung sẽ phát trực tiếp nếu URL luồng đi kèm với đối tượng LiveVideo (biểu thị nội dung phát) đang nhận được dữ liệu phát trực tiếp. Khi thành công, API sẽ phản hồi bằng ID của đối tượng LiveVideo.

Yêu cầu mẫu

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();

Ví dụ về phản hồi JSON

{
  "id": "10214937378883406"
}