Skip to content

Instantly share code, notes, and snippets.

@M-Igashi
Last active August 6, 2021 05:04
Show Gist options
  • Save M-Igashi/82796c58deb6ae44640fc6ae3001b978 to your computer and use it in GitHub Desktop.
Save M-Igashi/82796c58deb6ae44640fc6ae3001b978 to your computer and use it in GitHub Desktop.
API request sample for coincheck
var access = "YOUR-ACCESS-KEY-HERE"; //あなたのアクセスキーを入力
var secret = "YOUR-ACCESS-SECRET-HERE"; //あなたのアクセスシークレットを入力
var date = new Date();
var nonce = Math.floor((date.getTime()/1000)).toString(); //Unix時間をテキスト化
var url = "https://coincheck.com/api/accounts/balance"; //リクエストURL
//var body = {}; //postリクエストの場合はパラメタをJSON形式で記述
//var payload = JSON.stringify(body); //bodyをpayload化
var message = nonce+url; //postリクエストの場合はこの後ろに +payload を追加
var sig = Utilities.computeHmacSha256Signature(message, secret); //メッセージをHMAC-SHA256で暗号化
var signature = sig.reduce(function(str,chr){
chr = (chr < 0 ? chr + 256 : chr).toString(16);
return str + (chr.length==1?'0':'') + chr;
},''); //Google Apps Scriptはバイト配列で暗号を返すので16進数化
var headers = {
"ACCESS-KEY":access,
"ACCESS-NONCE":nonce,
"ACCESS-SIGNATURE":signature
}; //ヘッダー情報を格納
var options = {
"method": "get", //postかgetか
"headers": headers,
"contentType": "application/json"
//,"payload": payload //postリクエストの場合はpayloadをoptionsに格納
};
var response = UrlFetchApp.fetch(url, options); //HTTPリクエスト
function showbalance(){
Logger.log(response); //ログ表示
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment