[["parts" => [["text" => $prompt]]]], "generationConfig" => [ "maxOutputTokens" => 100, "temperature" => 0.8 ] ]; $ch = curl_init($endpoint . "?key=$apiKey"); curl_setopt($ch, CURLOPT_HTTPHEADER, ["Content-Type: application/json"]); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data)); // SSL FIX VOOR LOCALHOST WINDOWS curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { // Log de fout voor jezelf error_log("Gemini Fout: " . $response); return null; } $json = json_decode($response, true); if (isset($json['candidates'][0]['content']['parts'][0]['text'])) { return trim($json['candidates'][0]['content']['parts'][0]['text']); } return null; } /* ============================ CONTROLE & UITVOERING ============================ */ $today = date("Y-m-d"); $stmt_check = $db_conx->prepare("SELECT COUNT(*) AS count FROM shoutouts WHERE DATE(created_at) = ?"); $stmt_check->bind_param("s", $today); $stmt_check->execute(); $row = $stmt_check->get_result()->fetch_assoc(); if ($row['count'] >= $NUM_SHOUTS_PER_DAY) { die("✅ Vandaag zijn er al " . $row['count'] . " shout-outs. Klaar!\n"); } $remaining = $NUM_SHOUTS_PER_DAY - $row['count']; for ($i = 0; $i < $remaining; $i++) { $name = $names[array_rand($names)]; $shoutText = aiShoutoutText(); if ($shoutText) { $stmt = $db_conx->prepare("INSERT INTO shoutouts (name, shoutout, created_at) VALUES (?, ?, NOW())"); $stmt->bind_param("ss", $name, $shoutText); $stmt->execute(); echo "✔ Toegevoegd: $name - $shoutText\n"; // Wacht 2 seconden tussen aanvragen om quota-fouten te voorkomen sleep(2); } else { echo "❌ AI aanvraag mislukt (mogelijk limiet bereikt).\n"; break; // Stop de loop als de API weigert } } ?>