我正在运行这段代码,有些时候我得到一个错误,其他的我没有,我真的不能理解为什么。
let promiseLogIn = new Promise(function(reject,resolve){
gapi.auth.authorize(authData , function(response) {
var authButton = document.getElementById('auth-button');
if (response.error) {
console.log("AuthBad");
resolve();
authButton.hidden = false;
}
else {
console.log("AuthGood");
reject();
authButton.hidden = true;
}
});
});我将lib加载到html文件中,如下所示:
<script src="https://apis.google.com/js/client.js?onload=authorize"></script>
<script src="sources/scripts/dist/bundle.js"></script>其中bundle.j是我保存所有已编译ts文件的位置。
发布于 2018-01-02 06:00:54
很可能是因为您的作用域中没有auth2库,所以会出现此错误。为了将库添加到google范围中,Google的示例文档鼓励使用gapi.load()方法加载新的包。所以,下面是你如何做到的:
let promiseLogIn = new Promise(function(reject,resolve){
gapi.load('auth2', function(){
gapi.auth.authorize(authData , function(response) {
var authButton = document.getElementById('auth-button');
if (response.error) {
console.log("AuthBad");
resolve();
authButton.hidden = false;
}
else {
console.log("AuthGood");
reject();
authButton.hidden = true;
}
});
});
});https://stackoverflow.com/questions/45283814
复制相似问题