【发布时间】:2017-12-13 22:12:52
【问题描述】:
因此,当用户使用SeatGeek API 输入表演者的姓名时,我试图检索数据。目前,我只是在我的 URL 中输入查询字符串,以确保我的密钥正常工作。所以这个:
https://api.seatgeek.com/2/events?performers.slug=new-york-mets&client_id=MY_CLIENT_ID
有效,我可以获得包含纽约大都会队赛事信息的 JSON。
例子:
"meta": {
"total": 192,
"per_page": 10,
"page": 1,
"took": 2,
"geolocation": null
},
"events": [ARRAY OF EVENTS]
服务器端和获取数据:
在我的表单中,我正在向/events 发出 POST 请求:
app.post('/events', function(req, res) {
let band = req.body.bandName;
band = band.split(' ').join('-')
fetch(`https://api.seatgeek.com/2/events?performers.slug=${band}&client_id=MY_CLIENT_ID`)
.then(function(data){
res.json(data);
}).catch(function(error){
console.log(error);
});
});
当我点击 POST 请求时,我得到不同的数据。我什至不完全确定这是什么:
{
"url": "https://api.seatgeek.com/2/events?performers.slug=new-york-mets&client_id=OTk1Mzg2MXwxNTEzMTkwMDUyLjI3",
"status": 200,
"statusText": "OK",
"headers": {
...
"body": {
"_readableState": {
"objectMode": false,
"highWaterMark": 16384,
"buffer": {
"head": null,
"tail": null,
"length": 0
}, etc...
我是否执行了错误的获取请求?
【问题讨论】:
标签: javascript api express