自动和手动导入Json到Google Sheets



如何使用谷歌表格的Appscript导入json数据到谷歌表格我看了这个github链接:[import_json_appsscript.js][1]这里有ticketmaster.com的API: https://app.ticketmaster.com/discovery/v2/events.json?size=1&apikey=xxxxxxx

我应该使用github链接所有到appscript的代码吗?[1]: https://gist.github.com/paulgambill/cacd19da95a1421d3164

2-我如何用Python或Javascript自动化地做到这一点我有json数据,然后创建谷歌表格文件,然后自动表示其中的数据。

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();

您可以使用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)

最新更新