Uncaught ReferenceError: gapi is not defined wordpress?

A1WEBSITEPRO QuestionsCategory: QuestionsUncaught ReferenceError: gapi is not defined wordpress?
Anonymous asked 9 years ago

I keep getting this error. Uncaught ReferenceError: gapi is not defined. I can see it in the console log. Please assist. 

Uncaught ReferenceError: gapi is not defined wordpress? was last modified: May 25th, 2015 by Anonymous
0 Answers
Maximus Mccullough Staff answered 9 years ago

What is going on here is the order the scripts are being called in. Remember that HTML is read left to right, top to bottom. I had an issue with this because of my Google  plus badge that I have on this website.

<script type="text/javascript">gapi.person.go();</script>

The code above must be the last one called in when you are inserting your Google Plus Badge because you have to call in the external script first. However, to get away from this issue, use the asynchronous code provided by Google. It looks like this, below.

<!-- Place this tag in your head or just before your close body tag. --> <script src="https://apis.google.com/js/platform.js" async defer></script> <!-- Place this tag where you want the widget to render. --> <div class="g-person" data-href="//plus.google.com/u/0/7777777YOUR777ID" data-layout="landscape" data-rel="author"></div>

Uncaught ReferenceError: gapi is not defined

The error message “Uncaught ReferenceError: gapi is not defined” typically means that the variable “gapi” has not been defined in the current scope or that the script that defines it has not been loaded.

“Gapi” is a JavaScript library used to interact with Google’s APIs, so this error might occur if you are trying to use the gapi variable without first including the necessary script.

Only cool people share!

To resolve this error, make sure you have included the relevant script in your HTML file or script file. You can use the following script tag to include the gapi library:

<script src="https://apis.google.com/js/api.js"></script>

Make sure to include this script tag before you try to use the gapi variable in your code.

If you have already included the script, make sure that it has been loaded correctly and that the variable is defined in the correct scope. You can try adding a console.log statement to check if the variable is defined or not:

console.log(gapi);

If you still cannot resolve the issue, please provide more details on where and how you are using the gapi variable so I can help you better.

Answer for Uncaught ReferenceError: gapi is not defined wordpress? was last modified: March 18th, 2023 by Maximus Mccullough