如何使用谷歌表格的 Appscript 將 json 資料匯入谷歌表格我查看了這個 github 鏈接:[import_json_appsscript.js][1],我在這里有 ticketmaster.com 的 API:https://app.ticketmaster.com /discovery/v2/events.json?size=1&apikey=xxxxxxx
我應該使用 github 的代碼將其全部鏈接到 Appsscript 中嗎?[1]:https ://gist.github.com/paulgambill/cacd19da95a1421d3164
2-如何使用 Python 或 Javascript 以自動化方式執行此操作,我擁有 json 資料,然后自動創建 Google Sheets 檔案,然后在其中表示資料。
var url = "https://app.ticketmaster.com/discovery/v2/events.json?size=1&apikey=xxxxxxx";
var xhr = new XMLHttpRequest();
xhr.open("GET", url);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
console.log(xhr.status);
console.log(xhr.responseText);
console.log("Events");
}
};
xhr.send();
uj5u.com熱心網友回復:
您可以使用 Python 的 gspread 庫來完成。看看這里的檔案:https ://docs.gspread.org/en/latest/#example-usage 。完成所有設定后,以下代碼應該可以用于上傳 json
import json
import gspread
from google.oauth2.service_account import Credentials
# connect to your google sheet
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
credentials = Credentials.from_service_account_file('key.json', scopes=scope)
gc = gspread.authorize(credentials)
wks = gc.open("spreadsheet name").sheet1
# You can load a json file here, just using some sample data
x = '{ "receiver_email_1":6, "receiver_email_2":8, "receiver_email_3":10 }'
y = json.loads(x)
result = []
for key in y:
result.append([key,y[key]])
wks.update('A1', result)
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/479337.html
