0

I am trying to create an app that would get the live comments from one of my live videos on my FB page and would play a notification sound whenever someone comments. I'm quite new to APIs and I tried reading the Graph API documentation for live comments here: https://developers.facebook.com/docs/graph-api/server-sent-events/endpoints/live-comments

Here is a sample that was given to subscribe to the endpoint and get the live comments:

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

My access token works fine. Checked it on the Access Token Debugger. The access token has the proper permissions based on the documentation on the live-comments endpoint link above.

I tried the code out and it seems like the API call is successful because it's returning a status code of 200, but I'm getting this particular error message enter image description here

I tried searching for what to do and I can't find anything that can help me on fixing this. I am completely lost. I hope someone can help me fix this or even just point me to the right direction.

  • Hey Karver, this errors points to a CORS error, here you can read more about this error: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS. Basically this means that your server is trying to fetch something from a different remote server (The API). I suggest you read this section so you hopefully better understand what to do. https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS#preflighted_requests_in_cors if you still dont understand leave another comment and il see if i can help you any further. – Kevin_Vink Mar 22 '22 at 23:22
  • Thanks @Kevin_Vink! I'll take a look at the links. Hopefully this should be enough. – Karver Gillroy Mar 22 '22 at 23:35
  • `from origin 'null'` indicates that you are likely trying this from a document opened via the file system. You need to do this from a page that was loaded via HTTP. – CBroe Mar 23 '22 at 06:54

0 Answers0