Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
API request sample for bitFlyer
var access = "xxxxxxxxxxxxxxxxx"; //あなたのアクセスキーを入力
var secret = "YYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; //あなたのアクセスシークレットを入力
var endpoint = "https://api.bitflyer.jp"
var date = new Date();
var nonce = Math.floor((date.getTime()/1000)).toString(); //Unix時間をテキスト化
var method = "GET" //GETかPOSTかを大文字で指定
var path = "/v1/me/getbalance"; //リクエストPath
var url = endpoint + path;
//var body = {}; //postリクエストの場合はパラメタをJSON形式で記述
//var payload = JSON.stringify(body); //bodyをpayload化
var message = nonce+method+path; //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-TIMESTAMP': nonce,
'ACCESS-SIGN': signature,
'Content-Type': 'application/json' //ヘッダーにこれが必要。うっかり忘れると500エラーを返されてハマる。
} //ヘッダー情報の格納
var options = {
"method": method,
"headers": headers
//,"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