gpt4 book ai didi

node.js - 无法使用 API 创建 Eventbrite 事件

转载 作者:太空宇宙 更新时间:2023-11-04 02:04:07 24 4
gpt4 key购买 nike

我正在尝试使用 V3 API 创建事件。我发送的参数是:

var _event = {
"event" : {
"name": {
"html": "Test Event 01"
},
"description": {
"html": "Test Event 01"
},
"start": {
"timezone": "America/Chicago",
"utc": "2017-07-10T18:00:00Z"
},
"end": {
"timezone": "America/Chicago",
"utc": "2017-07-10T20:00:00Z"
},
"currency": "USD"
}
};

这就是我使用 NodeJS 发送请求的方式:

var request = require('request');
var _headers = {
'Authorization': 'Bearer ' + _token,
'Content-Type': 'application/json',
}

// Configure the request
var options = {
url: EVENTBRITE_API_URL + "events/",
method: 'POST',
headers: _headers,
form: _event
}

我还尝试了 Content-Type: application/x-url-form-encoded 和内部 optionsJSON.stringify(_event)。我还尝试将 _event 对象更改为:

var _event = {        
"name": {
"html": "Test Event 01"
},
"description": {
"html": "Test Event 01"
},
"start": {
"timezone": "America/Chicago",
"utc": "2017-07-10T18:00:00Z"
},
"end": {
"timezone": "America/Chicago",
"utc": "2017-07-10T20:00:00Z"
},
"currency": "USD"
};

我尝试了所有组合,但总是得到相同的响应:

{
"status_code": 400,
"error_description": "There are errors with your arguments: event[currency] - Unknown parameter, event.start.timezone - This field is required., event.currency - This field is required., event.start.utc - This field is required., event[start][timezone] - Unknown parameter, event.end.utc - This field is required., event[end][utc] - Unknown parameter, event[description][html] - Unknown parameter, event[name][html] - Unknown parameter, event[end][timezone] - Unknown parameter, event[start][utc] - Unknown parameter, event.end.timezone - This field is required., event.name.html - This field is required.",
"error": "ARGUMENTS_ERROR"
}

我可以查看任何示例创建事件请求吗?上述请求有什么问题吗?

最佳答案

我认为问题在于您当前正在发送表单帖子(通过使用 form 选项),但您的参数应类似于 { "event.currency": "USD", "event.name.html": "Test Event 01", ... }。如果要发送 JSON,则需要使用 json: true 并传递 JSON 可序列化的正文:

var request = require('request');
var _headers = {
'Authorization': 'Bearer ' + _token,
'Content-Type': 'application/json',
}

// Configure the request
var options = {
url: EVENTBRITE_API_URL + "events/",
method: 'POST',
headers: _headers,

// Instead of this:
// form: _event

// use this:
json: true, // says you're sending JSON
body: _event, // so the body should be JSON-serializable
};

如果您想坚持使用表单帖子,我认为应该这样做:

var _event = {
"event.name.html": "Test Event 01",
"event.description.html": "Test Event 01",
"event.start.timezone": "America/Chicago",
"event.start.utc": "2017-07-10T18:00:00Z",
"event.end.timezone": "America/Chicago",
"event.end.utc": "2017-07-10T20:00:00Z",
"event.currency": "USD",
};

var request = require('request');
var _headers = {
'Authorization': 'Bearer ' + _token,
'Content-Type': 'application/x-www-form-urlencoded',
}

// Configure the request
var options = {
url: EVENTBRITE_API_URL + "events/",
method: 'POST',
headers: _headers,
form: _event,
};

关于node.js - 无法使用 API 创建 Eventbrite 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44947047/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com