[英]Google Calendar Events API for Insert throwing 400
我已經簽出了與此問題相關的其他帖子,但它們並不相同:我使用的是“響應”,我從google api網站復制了日期/時間,因此格式正確,並且我一直在處理標題。 還有其他想法為什么不起作用?
我收到以下錯誤:
Error: failed [400] { "error": { "errors": [ { "domain": "global", "reason": "required", "message": "Missing end time." } ], "code": 400, "message": "Missing end time." } } [object Object]
我下面的代碼分解為以下步驟:我要進行POST的url,用戶訪問令牌,插入的日歷事件的選項(包括標題和帶有開始,結束和事件摘要的事件)以及實際的http發布和回調函數:
calendarSchedule() {
if(Meteor.user() && moment(Meteor.user().services.google.expiresAt) > moment()._d) {
var url = "https://www.googleapis.com/calendar/v3/calendars/primary/events";
var userAccessToken = Meteor.user().services.google.accessToken;
var options = {
headers : {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + userAccessToken,
'X-JavaScript-User-Agent': "Google APIs Explorer",
},
calendarId: 'primary',
resource : {
start: { dateTime: "2016-05-03T18:03:58+02:00" },
end: { dateTime: "2016-05-03T18:03:58+02:00" },
summary: "testSummar",
}
};
HTTP.post(url, options,
function(error,result) {
console.log("posted to calendar? "+ error+ result);
});
}
}
我想通了,認為應該在這里發布答案。
由於某種原因,在這種情況下,您使用數據而不是資源。 我不確定為什么在這種情況下要有人鳴叫,但這與google API日歷網站上的消息有所不同。
我的最終代碼有效:
calendarSchedule() {
if(Meteor.user() && moment(Meteor.user().services.google.expiresAt) > moment()._d) {
var url = "https://www.googleapis.com/calendar/v3/calendars/primary/events";
var userAccessToken = Meteor.user().services.google.accessToken;
var currentEvent = {
'summary': this.props.text,
// 'location': this.refs.location.textContent,
'start': {
'dateTime': moment()._d,
'timeZone': this.refs.timeZone,
},
'end': {
'dateTime': moment(moment()._d).add(1, 'hours'),
'timeZone': this.refs.timeZone,
},
'attendees': [],
'reminders': {
'useDefault': true,
}
};
var options = {
headers : {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + userAccessToken,
'X-JavaScript-User-Agent': "Google APIs Explorer",
},
calendarId: 'primary',
data: currentEvent,
};
var searchResult = HTTP.post(url, options,
function(error,result) {
console.log("posted to calendar? "+ error+ result);
});
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.