Загрузка api.js в расширение Chrome - PullRequest
0 голосов
/ 12 июня 2019

Я пытаюсь загрузить api.js [клиентская библиотека Javascript Gmail API] в расширение chrome, используя следующий код, но выдает эту ошибку:

Uncaught TypeError: gapi.loaded_0 не является функцией в cb = gapi.loaded_0: 1 ".

content.js

function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      console.log(this.responseText)
      eval(this.responseText);
      init();
    }
  };
  xhttp.open("GET", "https://apis.google.com/js/api.js");
  xhttp.send();
}

loadDoc();

function init() {
  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: "22086111114-8jnncd2tkjm2lrruoq5ji2vu7hoouddv.apps.googleusercontent.com"});
  });
}
...