Gdata JavaScript Authsub Continues Redirecting

I am using the Google Data JavaScript API and have problems with the AuthSub script working correctly. This is my script now:

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 launch this page, the page redirects me to the authentication page. After I authenticate it, send me to my page and then return me to the authentication page again. I turned on alerts to check if the token is installed and it does not seem to work. Does anyone have this problem?

+5
source share
4 answers

I had the same problem, so I built this function

function login() {
    var scope = "http://www.google.com/calendar/feeds/";
    if(!google.accounts.user.checkLogin(scope)) {
        if(google.accounts.user.getStatus() == 0) {
            var token = google.accounts.user.login();
        }
    }
}

google.accounts.user.getStatus(), 1, , , 2, , . getStatus.

+2

, cookie , Google . , , cookie , google. setTimeout -, , .

+1

.

0

cookie orphaned , Google.

Now I do checkLogin before I execute my login, and if it returns true, I explicitly call logOut().

The logOut call will delete all cookies that Google rejected but left in your browser. The reason it seems to keep going in a loop is because the cookie exists, but even on reauth it does not create a new one because you already have one. But, unfortunately, for our sake, one that is not valid.

0
source

All Articles