var url="http://ptx.transportdata.tw/MOTC/v2/Rail/TRA/Station?$format=JSON";取得所有火車站資訊
var xdate=new Date().toGMTString();//驗證用時間
var l2_id="xxxxxxxxxxxxxxxxxxx"; //申請到的id
var l2_key="xxxxxxxxxxxxxxxxxxx"; //申請到的key
//HMAC-SHA1 運算
var signature = Utilities.computeHmacSignature(Utilities.MacAlgorithm.HMAC_SHA_1,"x-date: "+xdate,l2_key);//進行加密運算
//轉成Base64
var signatured=Utilities.base64Encode(signature);//結果轉64B
var header = {
'Accept': 'application/json',
"Authorization": 'hmac username="'+l2_id+'",algorithm="hmac-sha1",headers="x-date",signature="'+signatured+'"',
'x-date':xdate,
'Accept-Encoding':'gzip'
}//放入header 多注意Authorization是否排正確
var options = {
'headers': header,
'method': 'get',
}
var getans=UrlFetchApp.fetch(url,options)//取得資料