2017-02-14 4 views
0

이 문제와 관련된 다른 게시물을 확인했지만 동일하지 않습니다. "응답"을 사용하고 있으며 Google API 웹 사이트에서 날짜/시간을 복사하여 형식이 올바른, 나는 헤더와 함께 놀았어요. 왜 이것이 작동하지 않는 다른 아이디어?삽입 캘린더 용 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); 
     }); 
    } 
    } 

답변

0

나는 그것을 파악하고 내가 여기에 대답을 게시해야한다고 생각.

어떤 이유로이 경우 자원 대신 데이터를 사용합니다. 왜 다른 사람이 그 시점에서 차임을하고 싶어하는지 확신 할 수 없지만 이것은 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); 
     }); 
    } 
    }