const GEMINI_API_KEY = '你的API密鑰';
function generateQuiz() {
const apiUrl = 'https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateContent?key=' + GEMINI_API_KEY;
const payload = {
"prompt": "請生成一個關於物理基礎的選擇題,包括問題、四個選項以及正確答案。",
};
const options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload),
};
const response = UrlFetchApp.fetch(apiUrl, options);
const data = JSON.parse(response.getContentText());
Logger.log("生成的題目:" + data.candidates[0].content);
}
步驟:
GEMINI_API_KEY
替換為你的實際密鑰。
function saveQuizToSheet() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
const quiz = {
question: "以下哪個是 HTML 的全稱?",
options: ["HyperText Markup Language", "HighText Machine Language", "HyperTool Multi-Language", "HyperText Multi-Logic"],
answer: 0,
};
sheet.appendRow([quiz.question, ...quiz.options, quiz.answer]);
Logger.log("題目已儲存到試算表");
}
步驟: