0

enter image description hereI am working on google calendar api to fetch events of users google calendar but events not displaying on calendar.I am fetching events using google api key and I get array of events sorces and pass it to eventSources but still not work.

Below is my google calendar code

$(document).ready(function() {
    var json;
    var selectd = '';
    var abs;
    var strings;
    $('.my_cal_list').on('change',function(){
        if($(this).is(":checked")) {
            selectd+= '{ googleCalendarId: "'+$(this).val()+'"},';
        }else{
            var val = '{ googleCalendarId: '+$(this).val()+'},';
            selectd = selectd.replace(val,'');
        }
        if(selectd != ''){
            var strings = selectd.split(',');
            var newArray = strings.filter(function(v){return v!==''});
            console.log(newArray);
        }
        $('#calendar').fullCalendar('refetchEvents');
        $('#calendar').fullCalendar( 'addEventSource', newArray );
        $('#calendar').fullCalendar('rerenderEvents');

    });





    $('#calendar').fullCalendar({

        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,listYear'
        },

        displayEventTime: false,
        googleCalendarApiKey: 'AIzaSyCYlSCYzkLc7zl4XwA9QPottosUbQ3h2J4',

        // US Holidays
        eventSources:  [
            newArray
        ],
        eventClick: function(event) {
            // opens events in a popup window
            window.open(event.url, 'gcalevent', 'width=700,height=600');
            return false;
        },

        loading: function(bool) {
            $('#loading').toggle(bool);
        }

    });


});
varsha
  • 49
  • 5
  • "still not work" is not an error message or problem description. Check your console and network tabs for errors. Also what does the output of `newArray` look like? In the main calendar declaration you seem to use it before it's even declared? And then later in the "change" event it's not clear what the final result should be. It needs to be an _object_ (not a _string_!) like this `{ googleCalendarId: 'abcd1234@group.calendar.google.com' }` as per the examples at https://fullcalendar.io/docs/google_calendar/ . To me it looks like you're creating a string. – ADyson Sep 25 '17 at 09:26
  • newArray look like this : { googleCalendarId: "udv7vsa49r98ml7qh2aojt4u30@group.calendar.google.com"} – varsha Sep 25 '17 at 09:29
  • yes but I think it's a string not an object. It needs to be an object, not a string which happens look like JSON. – ADyson Sep 25 '17 at 09:31
  • I have checked console but no error displaying. Please help me I am stuck in it two days – varsha Sep 25 '17 at 09:31
  • I just did. Do you understand the difference between a string and an object? – ADyson Sep 25 '17 at 09:34
  • Yes but this also object format { googleCalendarId: "udv7vsa49r98ml7qh2aojt4u30@group.calendar.google.com"} – varsha Sep 25 '17 at 09:35
  • Please help me I am stuck in it last two days and still not getting solution. – varsha Sep 25 '17 at 09:37
  • not it's not, it's a string, because you are writing it like a string, with quotes around it. The fact that it **looks like** an object is **not relevant** to its actual, real, data type as seen by JavaScript. `selectd+= '{ googleCalendarId: "'+$(this).val()+'"},';` creates a string (and not a string which could even be parsed as an object, due to the trailing comma). Whereas, `selectd = { googleCalendarId: $(this).val() };` would create an object, for example. – ADyson Sep 25 '17 at 10:16
  • Then how to convert it to object i tried JSON.parse() but it not working. – varsha Sep 25 '17 at 10:18
  • I got error like this : Uncaught SyntaxError: Unexpected token o in JSON at position 1 – varsha Sep 25 '17 at 10:21
  • don't parse it. Write it like an object in the first place, the way I just demonstrated. – ADyson Sep 25 '17 at 10:25
  • I have pass array like this and if user check multiple checkbox then it's value added into this array { googleCalendarId: 'ba7sndnbabs0bj74etqasi4s28@group.calendar.google.com'},{ googleCalendarId: 'udv7vsa49r98ml7qh2aojt4u30@group.calendar.google.com'},{ googleCalendarId: 'gk5e3vmdm2tl94305o6q44o88s@group.calendar.google.com'},{ googleCalendarId: 'g8tovjtd1pu7kiiutdf2p5a3fc@group.calendar.google.com'} – varsha Sep 25 '17 at 10:26
  • ok. And your point is? Make an array then, and add the objects to the array as needed. Then pass that array to fullCalendar using addEventSources. Try it, then if you still can't make that work, edit the question with your updated code, and state what problem you've got, and I will try to help you finish it. – ADyson Sep 25 '17 at 10:31

0 Answers0