1

I'm developing a SharePoint Online app in Visual Studio 2012. I have added a link to the Google API JavaScript file. And as you can see from the screenshot's below taken from Chrome developer tools the client.js file has loaded. However, when I go to the console and try to call the "gapi" method I get "gapi" is not defined which means none of the methods in the client.js file are available. In addition, all of the jQuery methods are available but none of the client.js methods are available. Click the link below to get the Visual Studio project files: https://drive.google.com/file/d/0Bxi8whcREfK_VktRZDdacjkyV00/edit?usp=sharing

VS Code

gapi

client

1 Answer 1

1

It seems Google Client APIs have not been loaded yet when you try to access it.

Loading the Google Client Library

To use the Google JavaScript client library, you first need to load it, the following example demonstrates how to load a Client Library:

<!DOCTYPE html>
<html>
  <head>
    <meta charset='utf-8' />
    <script src="https://apis.google.com/js/client.js"></script>
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
  </head>
  <body>


    <script type="text/javascript">
      // Enter the API key from the Google Develoepr Console - to handle any unauthenticated
      // requests in the code.
      // The provided key works for this sample only when run from
      // https://google-api-javascript-client.googlecode.com/hg/samples/authSample.html
      // To use in your own application, replace this API key with your own.
      var apiKey = 'AIzaSyAdjHPT5Pb7Nu56WJ_nlrMGOAgUAtKjiPM';



      function handleClientLoad() {
        gapi.client.setApiKey(apiKey);
        //... 
      }



      $(window).load(handleClientLoad);
    </script>

  </body>
</html>
1
  • Vadim, in this case that will not work!
    – SPHelper
    Jun 30, 2014 at 12:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.