GASでよく使うけど忘れる系のチートシート〜外部API使う時の系〜

 

以前に、スプシ系のチートシートは作ったんですが、

GASでよく使うけど忘れる系のチートシート〜スプシ系〜

外部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

 

投稿者:

kin29man

農学部卒の7年目エンジニアです👩‍💻 PHPとGASが好きです!

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です