我正在尝试使用以下代码将api.js [Gmail API Javascript客户端库]加载到chrome扩展程序中,但是会出现此错误:
未捕获的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"});
});
}