[英]same-domain with fullcalendar and google calendar
我正在嘗試在使用全日歷框架開發的網頁中顯示我的Google日歷中的一些數據。
但是我有一個問題叫同域起源...我不知道如何解決。 在文檔中,fullcalendar說:
<script type='text/javascript'>
$(document).ready(function() {
$('#calendar').fullCalendar({
events: 'http://www.google.com/your_feed_url/'
});
});
</script>
但是通過使用我的公共日歷執行此操作只會給我帶來麻煩。
我嘗試使用服務器中的php以json格式讀取日歷,但是結果非常相似。 沒有收到有關域的問題,但未顯示事件。 我收到有關未初始化formatDate的錯誤,因此我認為我沒有讀取事件。
關於如何解決此問題的任何想法? 我想,如果fullcalendar允許使用gcalendar做到這一點,那意味着它可以做到。
我在json中添加了一些事件:
{"version":"1.0","encoding":"UTF-8","feed": {"xmlns":"http://www.w3.org/2005/Atom","xmlns$openSearch":"http://a9.com/- /spec/opensearchrss/1.0/","xmlns$gCal":"http://schemas.google.com/gCal/2005","id": {"$t":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic"},"update d":{"$t":"2013-08-22T09:47:26.000Z"},"category": [{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/g/2005 #event"}],"title":{"$t":"aristeidhsxr@gmail.com","type":"text"},"subtitle": {"$t":"aristeidhsxr@gmail.com","type":"text"},"link": [{"rel":"alternate","type":"text/html","href":"http://www.google.com/calendar/embed? src=aristeidhsxr%40gmail.com"},{"rel":"http://schemas.google.com/g/2005#feed","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic"},{"rel":"http://schemas.google.com/g/2005#batch","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic/batch"},{"rel":"self","type":"application/atom+xml","href":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic?alt=json&max-results=25"}],"author":[{"name":{"$t":"ΑÏιστείδης ΧÏήστου"},"email":{"$t":"aristeidhsxr@gmail.com"}}],"generator":{"$t":"Google Calendar","version":"1.0","uri":"http://www.google.com/calendar"},"openSearch$totalResults":{"$t":19},"openSearch$startIndex":{"$t":1},"openSearch$itemsPerPage":{"$t":25},"gCal$timezone":{"value":"Europe/Madrid"},"gCal$timesCleaned":{"value":0},"entry":[{"id":{"$t":"http://www.google.com/calendar/feeds/aristeidhsxr%40gmail.com/public/basic/2gh1aqf61krdvgr85eseoclr64"},"published":{"$t":"2013-08-22T09:47:26.000Z"},"updated":{"$t":"2013-08-22T09:47:26.000Z"},"category":[{"scheme":"http://schemas.google.com/g/2005#kind","term":"http://schemas.google.com/g/2005#event"}],"title":{"$t":"dghhfdg","type":"html"},"summary":{"$t":"Cuándo: vie 30 de ago de 2013 21:30 al 22:30 \nCEST\u003cbr\u003e\n\n\n\u003cbr\u003eEstado del evento: bekräftad","type":"html"},"content":{"$t":"Cuándo: vie 30 de ago de 2013 21:30 al 22:30 \nCEST\u003cbr /\u003e\n\n\n\u003cbr /\u003eEstado del evento: bekräftad","type":"html"},"link":[{"rel":"alternate","type":"text/html","href":"http://www.google.com/calendar/event?eid=MmdoMWFxZjYxa3JkdmdyODVlc2VvY2xyNjQgYXJpc3RlaWRoc3hyQG0","title":"alternate"}
這是json文件的一部分,尚未完成。
正如一名用戶所說,我嘗試直接放置一些事件:
$(document).on('pageshow','#agenda',function(){
$('#calendar').fullCalendar({
events: [{
title: 'Event 1', start: '2013-08-26T19:10:00Z',
end: '2013-08-28T19:20:00Z'
},{
title: 'Event 2', start: '2013-08-27T16:25:00Z',
end: '2013-08-27T18:45:00Z'
}]
});
});
但我收到一個錯誤消息:
Uncaught TypeError: Cannot read property 'formatDate' of undefined gcal.js:11
(anonymous function) gcal.js:11
(anonymous function) gcal.js:107
您確定從php中的http://www.google.com/your_feed_url/
解析事件正確嗎? 活動開始日期和結束日期必須為ISO 8601
格式,例如2013-07-09T19:10:00-04:00
。 您可以使用fullcalendar $.fullCalendar.formatDate(from, format);
轉換日期和時間。
您也可以使用Google Calendar Api來獲取事件。
事件必須看起來像這樣:
events: [{
title: 'Event 1', start: '2013-07-09T19:10:00-04:00',
end: '2013-07-09T19:20:00-04:00', allDay: false
},{
title: 'Event 2', start: '2013-08-22T16:25:00-04:00',
end: '2013-08-22T18:45:00-04:00', allDay: true
}]
對於公開的Google日歷,您可以執行以下操作:
var url = 'http://google.com/calendar/feeds/test@group.calendar.google.com/public/full?alt=json';
$.ajax({
url: url,
dataType: 'jsonp',
success: function(response){
var googleEvents = new Array();
for(var i = 0; i < response.feed.entry.length; i ++){
googleEvents[i] = {
title : response.feed.entry[i].title.$t,
start: response.feed.entry[i].gd$when[0].startTime,
end: response.feed.entry[i].gd$when[0].endTime
};
}
//init events
calendar = $('#calendar-container').fullCalendar({
events: googleEvents
});
}
});
參數alt
指定響應格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.