接入教程
https://opentdb.com/api.php?amount=101. 获取随机题目:
2. 按分类与难度筛选。
3. 使用Session Token避免重复题目。
4. 返回JSON包含题目、正确答案与错误选项。
5. 每个IP每5秒一次限制,单次最多50题。
Python 获取题目
python
import requests
r = requests.get("https://opentdb.com/api.php", params={"amount": 10})
for q in r.json()["results"]:
print(q["question"], q["correct_answer"])
PHP 获取题目
php
<?php
$url = 'https://opentdb.com/api.php?amount=10';
$data = json_decode(file_get_contents($url), true);
foreach ($data['results'] as $q) { echo $q['question'] . PHP_EOL; }
JavaScript 获取题目
javascript
fetch('https://opentdb.com/api.php?amount=10')
.then(r => r.json())
.then(d => d.results.forEach(q => console.log(q.question)));
常见问题
需要Key吗?
不需要,Open Trivia DB完全免费且无需Key。
有什么限制?
每个IP每5秒可请求一次,单次最多50道题。
Aitishiku.com