【发布时间】:2018-05-25 21:53:47
【问题描述】:
function renderButton() {
gapi.signin2.render('my-signin2', {
'scope': 'profile email',
'width': 240,
'height': 50,
'longtitle': true,
'theme': 'light',
'onsuccess': onSuccess,
'onfailure': onFailure
});
}
function onFailure() {
console.log('why the');
}
function onSuccess(googleUser) {
console.log('onSuccess has been called');
}
按钮已正确呈现,但没有调用任何回调方法。
按钮加载后如何调用onSuccess?
【问题讨论】:
-
尝试在调用函数
'onsuccess': onSuccess()时加括号 -
您没有调用该函数。您只是在添加参考。
-
@Shubham 你是什么意思?
-
@Dumisani 你必须提供不带括号的函数,因为它们被谷歌用作回调
-
@Epitouille 使用
function name() {}构造函数时的位置无关紧要,它是在所有其他javascript运行之前定义的
标签: javascript html oauth oauth-2.0 google-oauth