YouTube Live-Chat API and pollingIntervalMillis
Asked Answered
R

0

8

I'm trying to get all comments of a YouTube live-chat. Im successfully getting them with a WWW request with my client in Unity. The YouTube API offers a nextPageToken = {RANDOM_TOKEN} to get results of the next page, since it only shows me 75 comments on the first page.

My client goes through all of those pages with it's provided nextPageTokens and gets all the comments and stores them locally. Unfortunately, it seems like YouTube only allows API request every 10 seconds defined in the pollingIntervalMillis = 10000 So when I want to get the next page of comments, I need to wait 10 seconds over and over again. Otherwise it gives me the error rateLimitExceeded.

When I browse the HTTP request in my browser (Safari), the problem does not occur and I can make any request I want as fast as I want (even all the other pages).

Is there any way how I can get all the comments of every page faster than just every 10 seconds? If I'm getting 500 comments and 75 comments are on every page, I would need to wait around a minute to get all the comments. Seems kinda strange. There must be a possibility.

Hope you guys can help me out here :)

Update 1 With the help of a user to add a user-agent to my request, now my request looks like this:

Dictionary<string, string> headers = new Dictionary<string, string>();
headers.Add("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Safari/602.1.50");
WWW www = new WWW(url_2, new byte[] {(byte) 0}, headers);
StartCoroutine(WaitForRequest(www));

The request works, but now I'm getting an error 401 Unauthorized. I checked the API website again and error 401 is not even listed in the possible errors that are included in the liveChatMessages list since the only I should need is my liveChatId and my API access key. I have both, but a login shouldn't even be required. If my code looks like this:

WWW www = new WWW(url_2);
StartCoroutine(WaitForRequest(www));

I'm getting a result, but this was my original code, so I would have to wait 10 seconds till my next request. Any help?

Update 2 I found out that the pollingIntervalMillis are depending on the stream actually being live and the amount of comments coming in. When my stream was offline my pollingIntervalMillis were at 10000. When I started my stream online my pollingIntervalMillis were at 6000. When I spammed my chat with a whole bunch of comments my pollingIntervalMillis went to around 1000. So my initial problem is not a real problem anymore since the refresh rates are dropping heavily when the stream is live and the chat is active.

Maybe this post can help others as well!

Rael answered 22/3, 2017 at 16:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.