以前に、スプシ系のチートシートは作ったんですが、
外部API使う時も毎回ググりまくるのでまとめておきます!
スクリプト プロパティ(環境変数)
// スクリプト プロパティの取得
const GITHUB_TOKEN = PropertiesService.getScriptProperties().getProperty('GITHUB_TOKEN');
ref: https://developers.google.com/apps-script/reference/properties?hl=en
API叩く時
const url = 'https://api.github.com/users/kin29/repos';
const option = {
'method' : 'get',
'headers': {
'Accept': 'application/vnd.github+json',
'Authorization': 'Bearer '+ GITHUB_TOKEN,
'X-GitHub-Api-Version': '2022-11-28'
}
};
const response = UrlFetchApp.fetch(url, option).getContentText();
// JSON.parse(response)するとobjectになって使いやすい
ref: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app