สร้าง API ใช้เอง ด้วย Google app script ง่ายมากๆ

อีกหนึ่งความสามารถของ Google app script คือเราสามารถใช้ spreadsheet ของเราเป็นฐานข้อมูลเพื่อสร้าง API ให้เว็บภายนอกมาดึงข้อมูลไปใช้ได้ (ซึ่งเราจะมาดึงข้อมูลไปทำเว็บแอพในบทความต่อไป) ไปดูกันเลยครับ

// Presented by BrilliantPy

function doGet() {
  let ss = SpreadsheetApp.getActive();
  let sheet = ss.getSheetByName('ชีต1');
  let values = sheet.getDataRange().getDisplayValues();
  values.shift();
  let result = values.map(([a,b,c,d,e,f,g,h,i]) => {
    return ({unix:a,date:b,symbol:c,open:d,high:e,low:f,close:g,vol_btc:h,vol_usdt:i});
  })
  let data = JSON.stringify(result);
  console.log('data:',data);
  return ContentService.createTextOutput(data).setMimeType(ContentService.MimeType.JSON);
}

32 thoughts on “สร้าง API ใช้เอง ด้วย Google app script ง่ายมากๆ

  1. marizon ilogert says:

    I’m impressed, I have to say. Really rarely do I encounter a blog that’s both educative and entertaining, and let me inform you, you may have hit the nail on the head. Your idea is outstanding; the issue is one thing that not enough people are speaking intelligently about. I am very completely happy that I stumbled throughout this in my search for one thing regarding this.

ใส่ความเห็น

อีเมลของคุณจะไม่แสดงให้คนอื่นเห็น ช่องข้อมูลจำเป็นถูกทำเครื่องหมาย *