การกำหนดเวลาให้กับการแพร่ภาพ

การกำหนดเวลาวิดีโอถ่ายทอดสดจะเลิกใช้งานในเวอร์ชั่น 12.0 และจะเลิกใช้งานสำหรับทุกเวอร์ชั่นในวันที่ 14 ธันวาคม 2021 การเรียกใช้ตำแหน่งข้อมูล POST /ID/live-video ด้วยพารามิเตอร์ planned_start_time จะส่งคืนข้อผิดพลาด

คุณสามารถใช้ API วิดีโอถ่ายทอดสดเพื่อสร้างการแพร่ภาพวิดีโอถ่ายทอดสดที่จะเริ่มถ่ายทอดสดตามเวลาที่กำหนดไว้สูงสุดเจ็ดวันนับจากวันที่สร้าง

การกำหนดเวลาให้กับการแพร่ภาพ

หากต้องการสร้างการแพร่ภาพวิดีโอถ่ายทอดสดด้วยวันที่เริ่มต้นในอนาคตกับผู้ใช้ เพจ กลุ่ม หรือเหตุการณ์ ให้ส่งคำขอไปยัง:

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

ใช้พารามิเตอร์ planned_start_time และการประทับเวลา UNIX เพื่อระบุเวลาเริ่มต้นที่ต้องการ

การทำแบบนี้จะสร้างอ็อบเจ็กต์วิดีโอถ่ายทอดสดบนโหนดที่กำหนดเป้าหมายและส่งคืน secure_stream_url และ id ของวิดีโอถ่ายทอดสด ใช้ URL สตรีมที่ปลอดภัยกับตัวเข้ารหัสของคุณเพื่อสตรีมข้อมูลวิดีโอถ่ายทอดสดไปยังอ็อบเจ็กต์ 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_UNPUBLISHED หรือ UNPUBLISHED

หากต้องการดูตัวอย่างของการแพร่ภาพวิดีโอถ่ายทอดสดที่เลิกเผยแพร่แล้ว ให้ส่งคำขอไปยัง:

GET /{live_video_id}?fields={fields}

ใช้พารามิเตอร์ {fields} เพื่อรับ dash_preview_url ของอ็อบเจ็กต์ LiveVideo

ตัวอย่างคำขอ

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_url และ id ของวิดีโอถ่ายทอดสด คัดลอกและวาง URL ลงใน 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 จะตอบกลับด้วย ID ของอ็อบเจ็กต์ 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

การแพร่ภาพจะเริ่มถ่ายทอดสดหาก URL การสตรีมที่เชื่อมโยงกับอ็อบเจ็กต์ LiveVideo ซึ่งแสดงถึงการแพร่ภาพนั้นได้รับข้อมูลการสตรีม เมื่อเสร็จสิ้นแล้ว API จะตอบกลับด้วย ID ของอ็อบเจ็กต์ 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"
}