Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9202635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:18:11+00:00 2026-06-17T23:18:11+00:00

I am writing a short application for exporting events to Google calendar. (Events are

  • 0

I am writing a short application for exporting events to Google calendar. (Events are obtained from code processing information from my website.) However, when I click the button, the script I wrote is giving me a strange error. The error I get the first time I click the button is: Uncaught TypeError: Cannot call method 'setApiKey' of undefined. However, the second time I click the button without refreshing the page, the error disappears and the code runs perfectly.

Here is my code, as you can see I defined the api key before setting it:

var exportCalendarToGoogle = function() {
    var clientId = '38247913478902437.google@user...';
    var scope = 'https://www.googleapis.com/auth/calendar';
    var apiKey = 'JDKLSFDIOP109321403AJSL';

    var withGApi = function() {
        gapi.client.setApiKey(apiKey);
        gapi.auth.init(checkAuth);
      }
    var checkAuth = function() {
        gapi.auth.authorize({client_id: clientId, scope: scope, immediate: false}, handleAuthResult);
    }

    var handleAuthResult = function(authResult) {
        if(authResult) {
            gapi.client.load("calendar", "v3", exportCalendar);
        } else {
            alert("Authentication failed: please enter correct login information.");
        }
    }
 //functions to format the calendar json input to Google calendar...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T23:18:12+00:00Added an answer on June 17, 2026 at 11:18 pm

    Sounds like gapi has not been fully loaded

    http://code.google.com/p/google-api-javascript-client/wiki/GettingStarted

    There are two callbacks:

    1) In the URL to load the gapi code:

    <script src="https://apis.google.com/js/client.js?onload=handleClientLoad"></script>
    

    2) You can also supply a callback function that will let you know when a specific API has loaded:

    gapi.client.load('plus', 'v1', function() { console.log('loaded.'); });

    I think your problem is 1)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an application that shows Japanese Traditional Time (JTT for short). There
I am writing a javascript application using the File API in Google Chrome. I
I am writing a Django application that stores IP addresses with optional routing information.
The application I'm writing includes a pipeline for creating events. An Event is proposed
I'm writing application for downloading CSV file from web and inserting data into table
In short, I am writing an Android application that I want to have pull
I'm writing a Catalyst application that's required to have a fairly short session expiration
I am writing an application to manage user access to files. The short version
In short: I want to monitor selected calls from an application to a DLL.
So, I am writing a short (and simple) regular expression, but I can think

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.