Last active
January 23, 2018 03:52
-
-
Save adminho/0159bb53c02bfdee1c4c31de3d8ecd92 to your computer and use it in GitHub Desktop.
ตัวอย่างโค้ดเรียกใช้งานบริการ API ของธนาคารแห่งประเทศไทย
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> | |
<script> | |
$(document).ready(function(){ | |
//อ้างอิงคู่มือ ตามลิงค์นี้ https://iapi.bot.or.th/Developer?lang=th | |
// ตัวอย่างดู อัตราแลกเปลี่ยนถัวเฉลี่ยถ่วงน้ำหนักระหว่างธนาคาร (รายวัน) | |
$("button").click(function(){ | |
$.ajax({ | |
type : "GET", | |
url : "https://iapi.bot.or.th/Stat/Stat-ReferenceRate/DAILY_REF_RATE_V1/?start_period=2002-01-12&end_period=2002-01-15", | |
beforeSend: function(xhr){xhr.setRequestHeader('api-key', 'U9G1L457H6DCugT7VmBaEacbHV9RX0PySO05cYaGsm');}, | |
success : function(result) { | |
$("#div1").html(JSON.stringify(result)); | |
console.log(JSON.stringify(result)); | |
}, | |
error : function(result) { | |
//handle the error | |
} | |
}); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<div id="div1"><h2>ผลลัพธ์ JSON จะแสดงไว้ตรงนี้</h2></div> | |
<br/> | |
<button>ทดสอบ API แบงค์ชาติ</button> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//อ้างอิงคู่มือ ตามลิงค์นี้ https://iapi.bot.or.th/Developer?lang=th | |
// ตัวอย่างดู อัตราแลกเปลี่ยนถัวเฉลี่ยถ่วงน้ำหนักระหว่างธนาคาร (รายวัน) | |
// must intall this package | |
// npm install request | |
var request = require('request'); | |
var querystring = require('querystring'); | |
data = { | |
'start_period': '2002-01-12', | |
'end_period': '2002-01-15' | |
} | |
options = { | |
url: 'https://iapi.bot.or.th/Stat/Stat-ReferenceRate/DAILY_REF_RATE_V1/?' + querystring.stringify(data), | |
headers: { | |
'api-key': 'U9G1L457H6DCugT7VmBaEacbHV9RX0PySO05cYaGsm' | |
} | |
}; | |
request(options, function (error, response, body) { | |
if (!error && response.statusCode == 200) { | |
console.log(body) // print response | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# อ้างอิงคู่มือ ตามลิงค์นี้ https://iapi.bot.or.th/Developer?lang=th | |
# ตัวอย่างดู อัตราแลกเปลี่ยนถัวเฉลี่ยถ่วงน้ำหนักระหว่างธนาคาร (รายวัน) | |
import requests | |
url = 'https://iapi.bot.or.th/Stat/Stat-ReferenceRate/DAILY_REF_RATE_V1/' | |
querystring = {'start_period': '2002-01-12', 'end_period': '2002-01-15'} | |
headers = {'api-key': 'U9G1L457H6DCugT7VmBaEacbHV9RX0PySO05cYaGsm'} | |
response = requests.request('GET', url, headers=headers, params=querystring) | |
print (response.text) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment