function getWeather() {
const apiUrl = 'https://api.open-meteo.com/v1/forecast?latitude=25.033&longitude=121.565¤t_weather=true';
const response = UrlFetchApp.fetch(apiUrl);
const data = JSON.parse(response.getContentText());
Logger.log("當前天氣:" + data.current_weather.temperature + "°C");
}
步驟:
const GEMINI_API_KEY = '你的API密鑰';
function generateMessage() {
const apiUrl = 'https://generativelanguage.googleapis.com/v1/models/gemini-pro:generateMessage?key=' + GEMINI_API_KEY;
const payload = {
"prompt": {
"text": "生成一段歡迎學習 Google Apps Script 的訊息。"
}
};
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);
}
步驟: