■ポイント
A:google側でのJSONデータの吐き出し方
B:WebRequest.get()とJSON.decode() この2つの関数使用。
■A
・v3とv4がある
・v3で吐き出すJSONはシートの全データを引き出してしまう上にネストもかなり厚いので解析に時間がかかる
・v4はv3よりデータ量少ないけど、APIキーをURLに埋め込まないといけないのでセキュリティの問題が有り
◇spreadsheet側でスクリプトを書く方法
・spreadsheetで、メニューの「ツール」→「スクリプトエディタ」から入る
■B
function onLoad()
log("onLoad")
starttime = os.time();
math.randomseed(os.time())
startLuaCoroutine(self,"doWebRequest")
end
function doWebRequest()
WebRequest.get("ここにspreadsheetからJSON取得するURLを", self,
"webRequestCallback")
return 1
end
function webRequestCallback(res)
questions = JSON.decode(res.text)
createButton()
end
function showQuestion(question)
self.setName(question["タイトル"])
local q = " "
if (question["Qエリア"] != "") then
q = q .. "・" .. question["Qエリア"] .. " "
end
if (question["Q年"] != "") then
q = q .. "[60981D]・" .. question["Q年"] .. " "
end
以下省略