是否可以在我的 Squarespace 网站上显示来自 SeatGeek API 呼叫的数据?

Is it possible to display data from SeatGeek API call on my Squarespace site?

是否可以连接到 SeatGeek API 以在 Squarespace 站点上显示本地事件数据?

Squarespace API docs 似乎都针对与商业相关的目标。

我熟悉如何在移动应用程序的上下文中连接到 SeatGeek API。但我不知道是否可以从 Squarespace 连接到 APIs(商业用途除外)。

SeatGeek 将是 unofficial integration。我已经在 squarespace 论坛上发帖,但没有任何回应,所以在这里问问是否有人知道这件事。

非常感谢您的帮助!

"Personal" plan tier support the addition of custom JavaScript via Code Blocks and Code Injection.

上方的 Squarespace 网站

因此,如果 SeatGeek 支持通过 JavaScript 使用他们的 API(他们似乎支持),那么您可以从您的 Squarespace 网站中获取数据。

代码添加到站点的什么位置以及使用什么初始化方法将视具体情况而定。例如,因素包括:您使用的是 Squarespace 7.0 还是 7.1,以及您使用的模板是否支持 AJAX Loading 并已启用。

然而,无论代码添加到何处以及使用何种初始化方法,在我看来,基于what I see here,通过JavaScript从SeatGeek获取数据是可能的。 (Select "JavaScript > XMLHttpRequest" 或 "JavaScript > Fetch" 从右上角“代码片段”面板默认显示“(Node.js) Unirest”:

var data = null;

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
    if (this.readyState === this.DONE) {
        console.log(this.responseText);
    }
});

xhr.open("GET", "https://seatgeek-seatgeekcom.p.rapidapi.com/events");
xhr.setRequestHeader("x-rapidapi-host", "seatgeek-seatgeekcom.p.rapidapi.com");
xhr.setRequestHeader("x-rapidapi-key", "SIGN-UP-FOR-KEY");

xhr.send(data);

或者,通过获取:

fetch("https://seatgeek-seatgeekcom.p.rapidapi.com/events", {
    "method": "GET",
    "headers": {
        "x-rapidapi-host": "seatgeek-seatgeekcom.p.rapidapi.com",
        "x-rapidapi-key": "SIGN-UP-FOR-KEY"
    }
})
.then(response => {
    console.log(response);
})
.catch(err => {
    console.log(err);
});

虽然它因具体情况而异,但在大多数情况下,您会希望使用站点范围的代码注入区域而不是代码块或页面级代码注入。然后,在 Squarespace 7.0 站点上,您需要将代码包装在:

window.Squarespace.onInitialize(Y, function() {
  // do stuff here
});

另一方面,对于 Squarespace 7.1 网站,通常会将代码包装在:

document.addEventListener('DOMContentLoaded', function() {
  // do stuff here
}, false);

最后,您需要考虑如何输出数据。您可以通过目标页面正文中的代码块添加 HTML 标记,或者将标记添加到页面作为 JavaScript.

的一部分