2017-08-31 115 views
0

我正在使用Java Google API客戶端,並且正在嘗試創建Google日曆事件。 我可以登錄並獲取我已經創建的事件。(Java)插入事件時Google日曆格式錯誤

我一直在關注該API的例子,我收到以下錯誤,看着其他類似的問題,但仍無法得到它的工作:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request 
{ 
    "code" : 400, 
    "errors" : [ { 
"domain" : "global", 
"message" : "Invalid value for: \"T\" found, can only parse bare date string: 2017-08-31T12:00:00.000-01:00 Have you accidentally used DateTime instead of a Date?", 
"reason" : "invalid" 
    } ], 
    "message" : "Invalid value for: \"T\" found, can only parse bare date string: 2017-08-31T12:00:00.000-01:00 Have you accidentally used DateTime instead of a Date?" 
} 

這是我的代碼,我m將字符串傳入我的日期時間:

DateTime startDate = new DateTime(startData); 
    EventDateTime start = new EventDateTime(); 
    start.setDate(startDate); 
    start.setTimeZone("Europe/Stockholm"); 
    DateTime endDate = new DateTime(endData); 
    EventDateTime end = new EventDateTime(); 
    end.setDate(endDate); 
    end.setTimeZone("Europe/Stockholm"); 
    Event event = new Event(); 
    event.setDescription(lessons.get(i).getDescription()); 
    event.setStart(start); 
    event.setEnd(end); 
    event.setLocation(lessons.get(i).getLocation()); 
    event.setSummary(lessons.get(i).getName()) 

任何想法發生了什麼問題?

回答

0

可能的重複。

不過,很快 - 是的,你正在嘗試使用一個需要DateTime格式的函數,但是你提供的參數是一個不同的日期對象。

「new DateTime(startData);」 startData不是DateTime,而是日期。

請結帳這個帖子:Google Calendar API (Java) - Invalid time format when creating Google Calendar Event

有您的問題,它兩種解決方案。

+0

你說得對,畢竟我沒有正確地檢查過其他答案。我非常厭倦這一點。我可以關閉這個問題嗎? – Melrache

+0

@Melrache,您可以通過勾選該複選標記並將其標記爲已回答來關閉該問題。 – noogui