Search code examples
facebookfacebook-javascript-sdkfacebook-live-api

Facebook Live Comments API 400 Bad Request


I am trying to get a stream of comments from a live video. Currently I am trying to use this as a guide:

https://developers.facebook.com/.../endpoints/live-comments

The problem is even if I don't use JavaScript and I just send the request with cURL and replace the video ID with the ID of the live video and put in either my user access token or I have also tried a page access token I just get back a 400 Bad Request. I am using the exact same example from the link above and just replacing the required variables.

My request URL is this:

https://streaming-graph.facebook.com/{liveID}/live_comments?access_token={accessToken}&comment_rate=one_per_two_seconds&fields=from{name,id},message`

except I remove the {} and replace them with the ID and the access token respectively. At the bottom of the documentation it says a 400 error means I should check the URL and parameters are correct. Do you see anything wrong with the above URL? I have sent the request straight through cURL, through Postman, and also using EventSource like in the documentation and get a 400 Bad Request each time.

var source = new EventSource(
        `https://streaming-graph.facebook.com/{liveID}/live_comments?access_token={accessToken}&comment_rate=one_per_two_seconds&fields=from{name,id},message`)

    source.onmessage = function (event) {
        console.log(event)
    }

    source.onerror = function (error) {
        console.log(error)
    }

    source.onopen = function (event) {
        console.log(event)
    }

The only one that fires from the above example is the source.onerror and I just get a 400 Bad Request.

I know my ID and Token are correct because if I use the graph API from here (https://developers.facebook.com/docs/graph-api/reference/live-video/comments/) to pull the comments it works, but that method wont give me a stream of comments as they come in it only gives whatever comments are there at the time of running the query.


Solution

  • Alright after some more testing I figured it out. Turns out I was providing the "Post ID" to this and not the "Live ID" which was a different graph query.

    Prior I was using:

    https://graph.facebook.com/v11.0/{Page_Name}/posts

    and getting the ID from the post that contained the live video. What I actually needed to do was:

    https://graph.facebook.com/v11.0/{Page_Name}/live_videos

    This returns the correct ID to feed into the above live_comments endpoint.