Get more than 50 questions

I’m stuggling to understand how to use Session Tokens to get more than 50 questions. I am using PHP and I can make curl requests to load questions from the API. If I generate a Session Token at https://opentdb.com/api_token.php?command=request and use it I can request the API multiple times with a loop.

However, I don’t understand how I get different number of questions: e.g if I set amount=30 I can call the API 3 times to get a total of 90 questions. If I set amount=25 I only loop 3 times to get 75 questions. If I set amount=40 the loop only runs twice to get 80 questions. I have put a sleep(1) after each API call. Subsequent calls just return a response_code of 4 which says there are no more questions.

How do I get ALL of the questions?

1 Like

I know that you’re using your own local PHP script for this but I was able to generate about 4 to 6 successful requests (I didn’t count) within my web browser by just visiting the URL while setting the amount to 50 and passing my session token. Each time it generated new questions, at least judging by the very first question in the response.

It doesn’t seem like there are any restrictions in place to limit users to 50 questions per day and judging by what you’re describing your code logic is correct. Have you tried checking for the HTTP code using curl_getinfo($ch, CURLINFO_HTTP_CODE) ? Maybe you’re getting an HTTP 429 but the API responds with a response_code of 4 instead.

Thanks, I’ll try that. I couldn’t find any info about API rate limits.