gapi.auth2 has been initialized with different options. Consider calling gapi.auth2.getAuthInstance() instead of gapi.auth2.init()

Viewed 1657

I need to connect to several Google agendas accross several accounts to get events. The below function is called for each agenda to be connected to, it works for the first queried account, afterwards I get the above error. How can I connect to the next accounts, is there some disconnection or unsetting necessary for the authentication?

function runClient(apikey, client_id, calendar_id, post_id){
    gapi.load('client:auth2', initClient);
    function initClient() {
        gapi.client.init({
                discoveryDocs: ["https://www.googleapis.com/discovery/v1/apis/calendar/v3/rest"],
        }).then(() => {
            gapi.auth2.init({
                client_id: client_id,
                apiKey: apikey,
                scope: "https://www.googleapis.com/auth/calendar.readonly",
            }).then(getUpcomingEvents(calendar_id, post_id));
        });
    }
}
1 Answers

For some reason, removing the scope parameter from gapi.client.init() is a workaround for this problem for me. Obviously, the scope will now be the default instead user defined

Related