views:

127

answers:

0

I am using the JavaScript Google Data API and having issues getting the AuthSub script to work correctly. This is my script currently:

google.load('gdata', '1');

function getCookie(c_name){
    if(document.cookie.length>0){
        c_start=document.cookie.indexOf(c_name + "=");
        if(c_start!=-1){
            c_start=c_start + c_name.length+1;
            c_end=document.cookie.indexOf(";",c_start);
            if(c_end==-1) c_end=document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

function main(){
    var scope = 'http://www.google.com/calendar/feeds/';
    if(!google.accounts.user.checkLogin(scope)){
        google.accounts.user.login();
    } else {
        /*
        * Retrieve all calendars
        */

        // Create the calendar service object
        var calendarService = new google.gdata.calendar.CalendarService('GoogleInc-jsguide-1.0');

        // The default "allcalendars" feed is used to retrieve a list of all
        // calendars (primary, secondary and subscribed) of the logged-in user
        var feedUri = 'http://www.google.com/calendar/feeds/default/allcalendars/full';

        // The callback method that will be called when getAllCalendarsFeed() returns feed data
        var callback = function(result) {

          // Obtain the array of CalendarEntry
          var entries = result.feed.entry;

          //for (var i = 0; i < entries.length; i++) {
            var calendarEntry = entries[0];
            var calendarTitle = calendarEntry.getTitle().getText();
            alert('Calendar title = ' + calendarTitle);
          //}
        }

        // Error handler to be invoked when getAllCalendarsFeed() produces an error
        var handleError = function(error) {
          alert(error);
        }

        // Submit the request using the calendar service object
        calendarService.getAllCalendarsFeed(feedUri, callback, handleError);
    }
}

google.setOnLoadCallback(main);

However when I run this the page redirects me to the authentication page. After I authenticate it send me back to my page and then quickly sends me back to the authenticate page again. I've included alerts to check if the token is being set and it doesn't seem to be working. Has anyone has this problem?