การโต้ตอบกับผู้รับชม

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

การรับความคิดเห็นและความรู้สึกปัจจุบัน

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

GET /{live-video-id}/comments
GET /{live-video-id}/reactions

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

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

request.executeAsync();
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
    initWithGraphPath:@"/{live-video-id}/comments"
           parameters:nil
           HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
    // Insert your code here
}];
FB.api(
  '/{live-video-id}/comments',
  'GET',
  {},
  function(response) {
      // Insert your code here
  }
);
try {
  // Returns a `FacebookFacebookResponse` object
  $response = $fb->get(
    '/{live-video-id}/comments',
    '{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": [
    {
      "created_time": "2018-08-30T18:47:02+0000",
      "from": {
        "name": "Steph C.",
        "id": "552524095105158"
      },
      "message": "This is such a great live stream.",
      "id": "911936075671494_911936769004758"
    },
    {
      "created_time": "2018-08-30T18:47:17+0000",
      "from": {
        "name": "Kevin D.",
        "id": "552524095105158"
      },
      "message": "Shoutout over here!",
      "id": "911936075671494_911936909004744"
    },
    {
      "created_time": "2018-08-30T18:48:14+0000",
      "from": {
        "name": "Clay T.",
        "id": "552524095105158"
      },
      "message": "Where is this place?",
      "id": "911936075671494_911937292338039"
    }
    ],
  "paging": {
    "cursors": {
      "before": "WTI5d...",
      "after": "WTI5d..."
    }
  }
}

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

การรับความคิดเห็นและความรู้สึกแบบเรียลไทม์

หากคุณต้องการรับความคิดเห็นและความรู้สึกในไคลเอ็นต์เบราว์เซอร์แบบเรียลไทม์ ให้ตั้งค่าเหตุการณ์ที่ส่งจากเซิร์ฟเวอร์ แล้วส่งคำขอไปยังตำแหน่งข้อมูลต่อไปนี้:

GET /{live-video-id}/live_comments
GET /{live-video-id}/live_reactions

โปรดทราบว่า URL โฮสต์สำหรับกิจกรรมการสตรีมจะเป็น https://streaming-graph.facebook.com

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

GET https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token={access-token}
var source = new EventSource("https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token={access-token}");
source.onmessage = function(event) {
  // Do something with event.message for example
};

ตัวอย่างการตอบกลับ

: ping
data:
  {
    "created_time":"2018-08-30T21:11:01+0000",
    "id":"911936075671494_912014908996944",
    "view_id":43329028,
    "from":
      {
        "id":"552524095105158",
        "name":"Kerry Fisher"
      },
    "message":"I love this video!"
  }
: ping
: ping

โปรดดูเอกสารอ้างอิงเรื่องความคิดเห็นต่อวิดีโอถ่ายทอดสดและความรู้สึกต่อวิดีโอถ่ายทอดสด เพื่อให้ทราบข้อมูลเกี่ยวกับช่องที่ส่งคืนได้ ความถี่ในการรับส่งข้อมูล และการกรอง