📄 Source: gemini_direct.php
<?php
// Get your Gemini API key from https://aistudio.google.com/
$geminiKey = 'YOUR_GEMINI_API_KEY_HERE'; // Replace with your actual key
$url = 'https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash-exp:generateContent?key=' . $geminiKey;
$data = [
'contents' => [
['parts' => [['text' => 'Say "Hello, Gemini is working!"']]]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo "HTTP Code: $httpCode\n";
echo "Response:\n";
print_r(json_decode($response, true));
?>
← Back